Skip to content

Commit f5745ba

Browse files
committed
Start no_std
1 parent 7c9854e commit f5745ba

File tree

8 files changed

+29
-39
lines changed

8 files changed

+29
-39
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,21 @@ encoding_rs = "0.8"
2222
[dependencies]
2323
cssparser-macros = {path = "./macros", version = "0.6"}
2424
dtoa-short = "0.3"
25-
itoa = "0.4"
25+
itoa = { version = "0.4", default-features = false }
2626
matches = "0.1"
2727
phf = {version = "0.8", features = ["macros"]}
2828
serde = {version = "1.0", optional = true}
2929
smallvec = "1.0"
30+
no-std-compat = { version = "0.2.0", features = ["alloc"] }
3031

3132
[build-dependencies]
3233
syn = { version = "1", features = ["extra-traits", "fold", "full"] }
3334
quote = "1"
3435
proc-macro2 = "1"
3536

3637
[features]
38+
default = []
39+
std = ["no-std-compat/std", "itoa/std"]
3740
bench = []
3841
dummy_match_byte = []
3942

src/color.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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::prelude::v1::*;
6+
57
use std::f32::consts::PI;
68
use std::fmt;
79

src/cow_rc_str.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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::prelude::v1::*;
6+
57
use std::borrow::{Borrow, Cow};
68
use std::cmp;
79
use std::fmt;

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
6767

6868
#![recursion_limit = "200"] // For color::parse_color_keyword
6969

70+
#![cfg_attr(not(feature = "std"), no_std)]
71+
extern crate no_std_compat as std;
72+
7073
pub use crate::color::{
7174
parse_color_keyword, AngleOrNumber, Color, ColorComponentParser, NumberOrPercentage, RGBA,
7275
};

src/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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::prelude::v1::*;
6+
57
use crate::cow_rc_str::CowRcStr;
68
use crate::tokenizer::{SourceLocation, SourcePosition, Token, Tokenizer};
79
use smallvec::SmallVec;

src/serializer.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
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::prelude::v1::*;
6+
57
use dtoa_short::{self, Notation};
68
use itoa;
79
use matches::matches;
810
use std::fmt::{self, Write};
9-
use std::io;
1011
use std::str;
1112

1213
use super::Token;
@@ -340,34 +341,7 @@ macro_rules! impl_tocss_for_int {
340341
where
341342
W: fmt::Write,
342343
{
343-
struct AssumeUtf8<W: fmt::Write>(W);
344-
345-
impl<W: fmt::Write> io::Write for AssumeUtf8<W> {
346-
#[inline]
347-
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
348-
// Safety: itoa only emits ASCII, which is also well-formed UTF-8.
349-
debug_assert!(buf.is_ascii());
350-
self.0
351-
.write_str(unsafe { str::from_utf8_unchecked(buf) })
352-
.map_err(|_| io::ErrorKind::Other.into())
353-
}
354-
355-
#[inline]
356-
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
357-
self.write_all(buf)?;
358-
Ok(buf.len())
359-
}
360-
361-
#[inline]
362-
fn flush(&mut self) -> io::Result<()> {
363-
Ok(())
364-
}
365-
}
366-
367-
match itoa::write(AssumeUtf8(dest), *self) {
368-
Ok(_) => Ok(()),
369-
Err(_) => Err(fmt::Error),
370-
}
344+
itoa::fmt(dest, *self).map(|_| ())
371345
}
372346
}
373347
};

src/tests.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#[cfg(feature = "bench")]
66
extern crate test;
77

8+
use std::prelude::v1::*;
9+
810
use encoding_rs;
911
use matches::matches;
1012
use serde_json::{self, json, Map, Value};
@@ -66,14 +68,14 @@ fn normalize(json: &mut Value) {
6668
fn assert_json_eq(results: Value, mut expected: Value, message: &str) {
6769
normalize(&mut expected);
6870
if !almost_equals(&results, &expected) {
69-
println!(
70-
"{}",
71-
::difference::Changeset::new(
72-
&serde_json::to_string_pretty(&results).unwrap(),
73-
&serde_json::to_string_pretty(&expected).unwrap(),
74-
"\n",
75-
)
76-
);
71+
// println!(
72+
// "{}",
73+
// ::difference::Changeset::new(
74+
// &serde_json::to_string_pretty(&results).unwrap(),
75+
// &serde_json::to_string_pretty(&expected).unwrap(),
76+
// "\n",
77+
// )
78+
// );
7779
panic!("{}", message)
7880
}
7981
}
@@ -282,7 +284,7 @@ fn outer_block_end_consumed() {
282284
.expect_function_matching("calc")
283285
.map_err(Into::<ParseError<()>>::into))
284286
.is_ok());
285-
println!("{:?}", input.position());
287+
// println!("{:?}", input.position());
286288
assert!(input.next().is_err());
287289
}
288290

src/tokenizer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
// https://drafts.csswg.org/css-syntax/#tokenization
66

7+
use std::prelude::v1::*;
8+
79
use self::Token::*;
810
use crate::cow_rc_str::CowRcStr;
911
use crate::parser::ParserState;

0 commit comments

Comments
 (0)