Skip to content

Commit 3dc9f50

Browse files
committed
Update for Rust changes.
1 parent 5327f91 commit 3dc9f50

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

parser.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tokenizer::*;
2020
// TODO: Use a trait?
2121
enum ComponentValueIterator {
2222
ParserIter(~Parser),
23-
VectorIter(~[ComponentValue]),
23+
VectorIter(vec::VecConsumeIterator<ComponentValue>),
2424
}
2525

2626

@@ -36,10 +36,8 @@ impl ComponentValueIterator {
3636
}
3737

3838
#[inline]
39-
pub fn from_vector(mut values: ~[ComponentValue]) -> ComponentValueIterator {
40-
// TODO: find a way to have parse_iter() or something instead of reverse() + pop()
41-
vec::reverse(values);
42-
VectorIter(values)
39+
pub fn from_vector(values: ~[ComponentValue]) -> ComponentValueIterator {
40+
VectorIter(values.consume_iter())
4341
}
4442

4543
#[inline]
@@ -56,8 +54,7 @@ impl Iterator<ComponentValue> for ComponentValueIterator {
5654
fn next(&mut self) -> Option<ComponentValue> {
5755
match self {
5856
&ParserIter(ref mut parser) => next_component_value(*parser),
59-
&VectorIter(ref mut reversed_vector)
60-
=> if reversed_vector.is_empty() { None } else { Some(reversed_vector.pop()) }
57+
&VectorIter(ref mut iter) => iter.next()
6158
}
6259
}
6360
}

tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use std::{io, os, str, vec, run, task};
5+
use std::{io, os, str, run, task};
66
use extra::{tempfile, json};
77
use extra::json::ToJson;
88

@@ -47,7 +47,7 @@ fn run_json_tests(json_data: &str, parse: &fn (input: ~str) -> json::Json) {
4747
};
4848
assert!(items.len() % 2 == 0);
4949
let mut input: Option<~str> = None;
50-
do vec::consume(items) |_, item| {
50+
for items.consume_iter().advance |item| {
5151
match (&input, item) {
5252
(&None, json::String(string)) => input = Some(string),
5353
(&Some(_), expected) => {
@@ -242,7 +242,7 @@ impl ToJson for ComponentValue {
242242
Number(ref value) => JList(~[JString(~"number")] + numeric(value)),
243243
Percentage(ref value) => JList(~[JString(~"percentage")] + numeric(value)),
244244
Dimension(ref value, ref unit)
245-
=> JList(~[JString(~"dimension")] + numeric(value) + [unit.to_json()]),
245+
=> JList(~[JString(~"dimension")] + numeric(value) + ~[unit.to_json()]),
246246

247247
// TODO:
248248
UnicodeRange(_start, _end) => fail!(),
@@ -262,13 +262,13 @@ impl ToJson for ComponentValue {
262262

263263
Function(ref name, ref arguments)
264264
=> JList(~[JString(~"function"), name.to_json()]
265-
+ vec::map(*arguments, |c| (*c).to_json())),
265+
+ arguments.map(|c| (*c).to_json())),
266266
ParenthesisBlock(ref content)
267-
=> JList(~[JString(~"()")] + vec::map(*content, |c| (*c).to_json())),
267+
=> JList(~[JString(~"()")] + content.map(|c| (*c).to_json())),
268268
SquareBraketBlock(ref content)
269-
=> JList(~[JString(~"[]")] + vec::map(*content, |c| (*c).to_json())),
269+
=> JList(~[JString(~"[]")] + content.map(|c| (*c).to_json())),
270270
CurlyBraketBlock(ref content)
271-
=> JList(~[JString(~"{}")] + vec::map(*content, |c| (*c).to_json())),
271+
=> JList(~[JString(~"{}")] + content.map(|c| (*c).to_json())),
272272

273273
BadURL => JList(~[JString(~"error"), JString(~"bad-url")]),
274274
BadString => JList(~[JString(~"error"), JString(~"bad-string")]),

0 commit comments

Comments
 (0)