pub enum Token<'a> {
Show 31 variants Ident(CowRcStr<'a>), AtKeyword(CowRcStr<'a>), Hash(CowRcStr<'a>), IDHash(CowRcStr<'a>), QuotedString(CowRcStr<'a>), UnquotedUrl(CowRcStr<'a>), Delim(char), Number { has_sign: bool, value: f32, int_value: Option<i32>, }, Percentage { has_sign: bool, unit_value: f32, int_value: Option<i32>, }, Dimension { has_sign: bool, value: f32, int_value: Option<i32>, unit: CowRcStr<'a>, }, WhiteSpace(&'a str), Comment(&'a str), Colon, Semicolon, Comma, IncludeMatch, DashMatch, PrefixMatch, SuffixMatch, SubstringMatch, CDO, CDC, Function(CowRcStr<'a>), ParenthesisBlock, SquareBracketBlock, CurlyBracketBlock, BadUrl(CowRcStr<'a>), BadString(CowRcStr<'a>), CloseParenthesis, CloseSquareBracket, CloseCurlyBracket,
}
Expand description

One of the pieces the CSS input is broken into.

Some components use Cow in order to borrow from the original input string and avoid allocating/copying when possible.

Variants§

§

Ident(CowRcStr<'a>)

§

AtKeyword(CowRcStr<'a>)

A <at-keyword-token>

The value does not include the @ marker.

§

Hash(CowRcStr<'a>)

A <hash-token> with the type flag set to “unrestricted”

The value does not include the # marker.

§

IDHash(CowRcStr<'a>)

A <hash-token> with the type flag set to “id”

The value does not include the # marker.

§

QuotedString(CowRcStr<'a>)

A <string-token>

The value does not include the quotes.

§

UnquotedUrl(CowRcStr<'a>)

A <url-token>

The value does not include the url( ) markers. Note that url( <string-token> ) is represented by a Function token.

§

Delim(char)

A <delim-token>

§

Number

Fields

§has_sign: bool

Whether the number had a + or - sign.

This is used is some cases like the <An+B> micro syntax. (See the parse_nth function.)

§value: f32

The value as a float

§int_value: Option<i32>

If the origin source did not include a fractional part, the value as an integer.

§

Percentage

Fields

§has_sign: bool

Whether the number had a + or - sign.

§unit_value: f32

The value as a float, divided by 100 so that the nominal range is 0.0 to 1.0.

§int_value: Option<i32>

If the origin source did not include a fractional part, the value as an integer. It is not divided by 100.

§

Dimension

Fields

§has_sign: bool

Whether the number had a + or - sign.

This is used is some cases like the <An+B> micro syntax. (See the parse_nth function.)

§value: f32

The value as a float

§int_value: Option<i32>

If the origin source did not include a fractional part, the value as an integer.

§unit: CowRcStr<'a>

The unit, e.g. “px” in 12px

§

WhiteSpace(&'a str)

§

Comment(&'a str)

A comment.

The CSS Syntax spec does not generate tokens for comments, But we do, because we can (borrowed &str makes it cheap).

The value does not include the /* */ markers.

§

Colon

A : <colon-token>

§

Semicolon

A ; <semicolon-token>

§

Comma

A , <comma-token>

§

IncludeMatch

§

DashMatch

§

PrefixMatch

§

SuffixMatch

§

SubstringMatch

§

CDO

A <!-- <CDO-token>

§

CDC

§

Function(CowRcStr<'a>)

A <function-token>

The value (name) does not include the ( marker.

§

ParenthesisBlock

A <(-token>

§

SquareBracketBlock

A <[-token>

§

CurlyBracketBlock

A <{-token>

§

BadUrl(CowRcStr<'a>)

A <bad-url-token>

This token always indicates a parse error.

§

BadString(CowRcStr<'a>)

A <bad-string-token>

This token always indicates a parse error.

§

CloseParenthesis

A <)-token>

When obtained from one of the Parser::next* methods, this token is always unmatched and indicates a parse error.

§

CloseSquareBracket

A <]-token>

When obtained from one of the Parser::next* methods, this token is always unmatched and indicates a parse error.

§

CloseCurlyBracket

A <}-token>

When obtained from one of the Parser::next* methods, this token is always unmatched and indicates a parse error.

Implementations§

source§

impl<'a> Token<'a>

source

pub fn is_parse_error(&self) -> bool

Return whether this token represents a parse error.

BadUrl and BadString are tokenizer-level parse errors.

CloseParenthesis, CloseSquareBracket, and CloseCurlyBracket are unmatched and therefore parse errors when returned by one of the Parser::next* methods.

source§

impl<'a> Token<'a>

source

pub fn serialization_type(&self) -> TokenSerializationType

Categorize a token into a type that determines when /**/ needs to be inserted between two tokens when serialized next to each other without whitespace in between.

See the TokenSerializationType::needs_separator_when_before method.

Trait Implementations§

source§

impl<'a> Clone for Token<'a>

source§

fn clone(&self) -> Token<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Token<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for Token<'a>

source§

fn eq(&self, other: &Token<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> ToCss for Token<'a>

source§

fn to_css<W>(&self, dest: &mut W) -> Result
where W: Write,

Serialize self in CSS syntax, writing to dest.
source§

fn to_css_string(&self) -> String

Serialize self in CSS syntax and return a string. Read more
source§

impl<'a> StructuralPartialEq for Token<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Token<'a>

§

impl<'a> RefUnwindSafe for Token<'a>

§

impl<'a> !Send for Token<'a>

§

impl<'a> !Sync for Token<'a>

§

impl<'a> Unpin for Token<'a>

§

impl<'a> UnwindSafe for Token<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.