Name Description Size
color.rs General color-parsing utilities, independent on the specific color storage and parsing implementation. For a more complete css-color implementation take a look at cssparser-color crate, or at Gecko's color module. 12327
cow_rc_str.rs 4752
from_bytes.rs 2368
lib.rs ! Implementation of [CSS Syntax Module Level 3](https://drafts.csswg.org/css-syntax/) for Rust. # Input Everything is based on `Parser` objects, which borrow a `&str` input. If you have bytes (from a file, the network, or something) and want to support character encodings other than UTF-8, see the `stylesheet_encoding` function, which can be used together with rust-encoding or encoding-rs. # Conventions for parsing functions Take (at least) a `input: &mut cssparser::Parser` parameter Return `Result<_, ()>` When returning `Ok(_)`, the function must have consumed exactly the amount of input that represents the parsed value. When returning `Err(())`, any amount of input may have been consumed. As a consequence, when calling another parsing function, either: Any `Err(())` return value must be propagated. This happens by definition for tail calls, and can otherwise be done with the `?` operator. Or the call must be wrapped in a `Parser::try` call. `try` takes a closure that takes a `Parser` and returns a `Result`, calls it once, and returns itself that same result. If the result is `Err`, it restores the position inside the input to the one saved before calling the closure. Examples: ```{rust,ignore} // 'none' | <image> fn parse_background_image(context: &ParserContext, input: &mut Parser) -> Result<Option<Image>, ()> { if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { Ok(None) } else { Image::parse(context, input).map(Some) // tail call } } ``` ```{rust,ignore} // [ <length> | <percentage> ] [ <length> | <percentage> ]? fn parse_border_spacing(_context: &ParserContext, input: &mut Parser) -> Result<(LengthOrPercentage, LengthOrPercentage), ()> { let first = LengthOrPercentage::parse?; let second = input.try_parse(LengthOrPercentage::parse).unwrap_or(first); (first, second) } ``` 3717
macros.rs 7714
nth.rs 5016
parser.rs 40996
rules_and_declarations.rs ... 21515
serializer.rs ")?; dest.write_str(content)?; dest.write_str(" 19243
size_of_tests.rs 2095
tests.rs 44662
tokenizer.rs ` ` 48018
unicode_range.rs https://drafts.csswg.org/css-syntax/#urange 5628