Pick code review nits.

This commit is contained in:
Adam Kelly
2019-04-10 09:26:18 +01:00
parent 9a92159413
commit 8f840d5376
3 changed files with 11 additions and 11 deletions

View File

@@ -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> {

View File

@@ -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());
}
}

View File

@@ -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))?;