Skip to content

Commit 9fb9361

Browse files
committed
Rust upgrade
1 parent 0688d6e commit 9fb9361

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs')
1313
all: libcssparser.dummy
1414

1515
libcssparser.dummy: lib.rs $(RUST_SRC)
16-
$(RUSTC) $(RUSTFLAGS) $< --lib --out-dir .
16+
$(RUSTC) $(RUSTFLAGS) $< --crate-type=lib --out-dir .
1717
touch $@
1818

1919
cssparser-test: lib.rs $(RUST_SRC)

ast.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +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::fmt;
56
use std::vec;
67

78

@@ -119,9 +120,9 @@ pub enum ErrorReason {
119120
// This is meant to be extended
120121
}
121122

122-
impl ToStr for SyntaxError {
123-
fn to_str(&self) -> ~str {
124-
format!("{:u}:{:u} {:?}", self.location.line, self.location.column, self.reason)
123+
impl fmt::Show for SyntaxError {
124+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125+
write!(f.buf, "{:u}:{:u} {:?}", self.location.line, self.location.column, self.reason)
125126
}
126127
}
127128

@@ -138,7 +139,7 @@ impl<'a> SkipWhitespaceIterable<'a> for &'a [ComponentValue] {
138139

139140
#[deriving(Clone)]
140141
pub struct SkipWhitespaceIterator<'a> {
141-
iter_with_whitespace: vec::VecIterator<'a, ComponentValue>,
142+
iter_with_whitespace: vec::Items<'a, ComponentValue>,
142143
}
143144

144145
impl<'a> Iterator<&'a ComponentValue> for SkipWhitespaceIterator<'a> {
@@ -162,7 +163,7 @@ impl MoveSkipWhitespaceIterable for ~[ComponentValue] {
162163
}
163164

164165
pub struct MoveSkipWhitespaceIterator {
165-
iter_with_whitespace: vec::MoveIterator<ComponentValue>,
166+
iter_with_whitespace: vec::MoveItems<ComponentValue>,
166167
}
167168

168169
impl Iterator<ComponentValue> for MoveSkipWhitespaceIterator {

color.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use std::ascii::StrAsciiExt;
6+
use std::cmp;
67

78
use ast::*;
89

@@ -250,7 +251,7 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
250251

251252
let mut iter = arguments.skip_whitespace();
252253
macro_rules! expect_comma(
253-
() => ( if iter.next() != Some(&Comma) { return None } );
254+
() => ( match iter.next() { Some(&Comma) => {}, _ => { return None } } );
254255
)
255256
macro_rules! expect_percentage(
256257
() => ( match iter.next() {
@@ -297,9 +298,9 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
297298
let hue = expect_number!() / 360.;
298299
let hue = hue - hue.floor();
299300
expect_comma!();
300-
let saturation = (expect_percentage!() / 100.).max(&0.).min(&1.);
301+
let saturation = cmp::min(cmp::max((expect_percentage!() / 100.), 0.), 1.);
301302
expect_comma!();
302-
let lightness = (expect_percentage!() / 100.).max(&0.).min(&1.);
303+
let lightness = cmp::min(cmp::max((expect_percentage!() / 100.), 0.), 1.);
303304

304305
// http://www.w3.org/TR/css3-color/#hsl-color
305306
fn hue_to_rgb(m1: f64, m2: f64, mut h: f64) -> f64 {
@@ -321,7 +322,7 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
321322

322323
let alpha = if has_alpha {
323324
expect_comma!();
324-
(expect_number!()).max(&0.).min(&1.) as f32
325+
cmp::min(cmp::max((expect_number!()), 0.), 1.) as f32
325326
} else {
326327
1.
327328
};

from_bytes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +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::cmp;
56
use std::str;
67

78
use encoding::label::encoding_from_whatwg_label;
@@ -44,7 +45,7 @@ pub fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str>
4445
if css.starts_with("@charset \"".as_bytes()) {
4546
// 10 is "@charset \"".len()
4647
// 100 is arbitrary so that no encoding label is more than 100-10 bytes.
47-
match css.slice(10, css.len().min(&100)).position_elem(&('"' as u8)) {
48+
match css.slice(10, cmp::min(css.len(), 100)).position_elem(&('"' as u8)) {
4849
None => (),
4950
Some(label_length)
5051
=> if css.slice_from(10 + label_length).starts_with("\";".as_bytes()) {

lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#[crate_id = "github.com/mozilla-servo/rust-cssparser#cssparser:0.1"];
66
#[feature(globs, macro_rules)];
77

8-
extern mod extra;
9-
extern mod encoding; // https://github.com/lifthrasiir/rust-encoding
8+
extern crate extra;
9+
extern crate encoding; // https://github.com/lifthrasiir/rust-encoding
1010

1111
pub use tokenizer::tokenize;
1212
pub use parser::{parse_stylesheet_rules, parse_rule_list, parse_declaration_list,

0 commit comments

Comments
 (0)