mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Pick code review nits.
This commit is contained in:
@@ -237,34 +237,34 @@ impl ItemProtocol for PyDictRef {
|
||||
// Implement IntoIterator so that we can easily iterate dictionaries from rust code.
|
||||
impl IntoIterator for PyDictRef {
|
||||
type Item = (PyObjectRef, PyObjectRef);
|
||||
type IntoIter = DictIterator;
|
||||
type IntoIter = DictIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
DictIterator::new(self)
|
||||
DictIter::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for &PyDictRef {
|
||||
type Item = (PyObjectRef, PyObjectRef);
|
||||
type IntoIter = DictIterator;
|
||||
type IntoIter = DictIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
DictIterator::new(self.clone())
|
||||
DictIter::new(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DictIterator {
|
||||
pub struct DictIter {
|
||||
dict: PyDictRef,
|
||||
position: usize,
|
||||
}
|
||||
|
||||
impl DictIterator {
|
||||
pub fn new(dict: PyDictRef) -> DictIterator {
|
||||
DictIterator { dict, position: 0 }
|
||||
impl DictIter {
|
||||
pub fn new(dict: PyDictRef) -> DictIter {
|
||||
DictIter { dict, position: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for DictIterator {
|
||||
impl Iterator for DictIter {
|
||||
type Item = (PyObjectRef, PyObjectRef);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
||||
@@ -237,7 +237,7 @@ pub fn get_attributes(obj: &PyObjectRef) -> PyAttributes {
|
||||
|
||||
// Get instance attributes:
|
||||
if let Some(dict) = &obj.dict {
|
||||
for (key, value) in dict.into_iter() {
|
||||
for (key, value) in dict {
|
||||
attributes.insert(key.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ impl<'s> serde::Serialize for PyObjectSerializer<'s> {
|
||||
serialize_seq_elements(serializer, &elements)
|
||||
} else if objtype::isinstance(self.pyobject, &self.vm.ctx.dict_type()) {
|
||||
let dict: PyDictRef = self.pyobject.clone().downcast().unwrap();
|
||||
let pairs: Vec<(PyObjectRef, PyObjectRef)> = dict.into_iter().collect();
|
||||
let pairs: Vec<_> = dict.into_iter().collect();
|
||||
let mut map = serializer.serialize_map(Some(pairs.len()))?;
|
||||
for (key, e) in pairs.iter() {
|
||||
map.serialize_entry(&self.clone_with_object(key), &self.clone_with_object(&e))?;
|
||||
|
||||
Reference in New Issue
Block a user