properly wrap Vec's IntoIter property

This commit is contained in:
Matthew Piziak 2016-08-08 18:21:57 -04:00
parent b1b5526cf0
commit 79630e0cd1

View file

@ -4,6 +4,7 @@ use std::string;
use std::i64; use std::i64;
use std::str::FromStr; use std::str::FromStr;
use std::mem; use std::mem;
use std::vec;
use parser::*; use parser::*;
use scanner::{TScalarStyle, ScanError, TokenType}; use scanner::{TScalarStyle, ScanError, TokenType};
@ -344,21 +345,19 @@ impl IntoIterator for Yaml {
type IntoIter = YamlIter; type IntoIter = YamlIter;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
let mut yaml = self.into_vec().unwrap_or(vec![]); YamlIter {yaml: self.into_vec().unwrap_or(vec![]).into_iter()}
yaml.reverse();
YamlIter {yaml: yaml}
} }
} }
pub struct YamlIter { pub struct YamlIter {
yaml: Vec<Yaml>, yaml: vec::IntoIter<Yaml>,
} }
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> {
self.yaml.pop() self.yaml.next()
} }
} }