remove clone from into_iter

This commit is contained in:
Matthew Piziak 2016-08-08 17:52:24 -04:00
parent b600b3bafe
commit 9e77a839d3

View file

@ -344,22 +344,21 @@ impl IntoIterator for Yaml {
type IntoIter = YamlIter; type IntoIter = YamlIter;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
YamlIter {yaml: self, index: 0} let mut yaml = self.into_vec().unwrap_or(vec![]);
yaml.reverse();
YamlIter {yaml: yaml}
} }
} }
pub struct YamlIter { pub struct YamlIter {
yaml: Yaml, yaml: Vec<Yaml>,
index: usize,
} }
impl Iterator for YamlIter { impl Iterator for YamlIter {
type Item = Yaml; type Item = Yaml;
fn next(&mut self) -> Option<Yaml> { fn next(&mut self) -> Option<Yaml> {
let result = self.yaml[self.index].clone(); self.yaml.pop()
self.index += 1;
Some(result)
} }
} }