Struct Token

Source
pub struct Token(/* private fields */);
Expand description

An abstract representation of the chunk of the source text, retaining certain “facts” about the source.

§Design

The Token type is an immutable packing of two u32s that represents a unit in the source text, but without the associated offset data that points to its position in the source text. This is important because it means that equivalent Tokens are equal even in different parts of the document. For the most part a Token doesn’t represent data that can be put into a text file because it lacks the underlying character data. It is lossy. For example a Token with Kind::Ident just represents an ident, but it doesn’t retain what the keyword is). Storing raw-character data would require either storing tokens on the heap (and therefore they couldn’t be Sized) or by keeping a reference to &'a str which means larger token sizes and lifetime tracking. By not storing character data we can keep Token Sized and keep it to size_of 8, avoiding the heap, avoiding references/lifetimes, and keeping Token entirely in the stack. For a lot of tokens this is fine because the underlying character data isn’t that useful past a certain point.

A Token retains certain “facts” about the underlying unit of text, though. For example it retains the Kind, how many characters the token consumed, and various other pieces of information, depending on the Kind. In some cases, it’s entirely possible to represent the full token, including character data, into the available bits (for example Kind::Delim stores its char, Kind::Number stores its f32). Taking the time in the tokenizer to gather these facts and values can keep cache-lines hot, which speeds up subsequent checks in the parser.

If you’re familiar with “red green” syntax trees such as Swiftlang’s libsyntax, or Rust-Analyzer’s Rowan or Roslyn this might be a little familiar in some concepts. However Token does not represent a tree, and relies on resorting back to the string data to find out keyword values.

This representation of facts, kind, length, or other metadata can be quite complex - so here’s a full breakdown:

§Anatomy of Token

A Token is a struct of (u32, u32). The second u32 is usually the token length (hence keeping them separate). The first u32, however, is split into 3 (sometimes 5) parts. The two u32s can be thought of like so:

  |-----|-------|--------------------------|---------------------------------|
  | TF  | K     | VD                       | Value                           |
0b| 000 | 00000 | 000000000000000000000000 | 0000000000000000000000000000000 |
  |-----|-------|--------------------------|---------------------------------|
  | 3-- | 5---- | 24---------------------- | 32----------------------------- |

§TF = Type Flags (or “Token Facts”)

This represents a bit-mask in the upper-most 3 bits. The flags are general purpose and change meaning depending on the Token’s Kind. Each flag generally maps to a method so it’s not necessary to remenber the contents of this table, but it can serve as a useful reference. Note that not all methods return a bool, so footnotes have been added to explain these further.

Kind::FlagDescriptionMethod
Kind::Number001Floating PointToken::is_float()
010Has a “Sign” (-/+)Token::has_sign()
100(Reserved)
Kind::Dimension001Floating PointToken::is_float()
010Has a “Sign” (-/+)Token::has_sign()
100Unit is a known dimensionToken::dimension_unit()1
Kind::String001Uses Double QuotesToken::quote_style()2
010Has a closing quoteToken::has_close_quote()
100Contains escape charactersToken::contains_escape_chars()
Kind::Ident001Contains non-lower-ASCIIToken::is_lower_case()
010Is a “Dashed Ident”Token::is_dashed_ident()
100Contains escape charactersToken::contains_escape_chars()
Kind::Function001Contains non-lower-ASCIIToken::is_lower_case()
010Is a “Dashed Ident”Token::is_dashed_ident()
100Contains escape charactersToken::contains_escape_chars()
Kind::AtKeyword001Contains non-lower-ASCIIToken::is_lower_case()
010Is a “Dashed Ident”Token::is_dashed_ident()
100Contains escape charactersToken::contains_escape_chars()
Kind::Hash001Contains non-lower-ASCIIToken::is_lower_case()
010First character is ASCIIToken::hash_is_id_like()
100Contains escape charactersToken::contains_escape_chars()
Kind::Url001Has a closing paren )Token::url_has_closing_paren()
010Contains whitespace after (Token::url_has_leading_space()
100Contains escape charactersToken::contains_escape_chars()
Kind::CdcOrCdo001Is CDO (000 would be CDC)Token::is_cdc()
010(Reserved)
100(Reserved)
Kind::Whitespace---Whitespace styleToken::whitespace_style()3
Kind::Delim---Associate whitespace rulesToken::associated_whitespace()4
Kind::Comment---(Special)Token::comment_style()5

§K = Kind Bits

The K value - upper-most bits 4-9 stores the 5-bit Kind.

§VD = Value Data

The VD value - the lower-most 24-bits - stores data depending on the Token Kind. For most kinds this data is reserved (just 0s). The value data cannot be interrogated manually, but it packs in additional data about the underlying string to make the string easier to parse without doing the same lookups that the tokenizer already had to - such as determining lengths of the various parts of the token, or packing values so that consulting the string can be avoided (which keeps cache-lines hot).

Below describes the special kinds which use the Value Data to store yet more information about the token…

§Value Data for Kind::Number

If the Kind is Kind::Number, Value Data represents the length of that number (this means the parser is restricted from representing numbers longer than 16,777,216 characters which is probably an acceptable limit). Note that this does not affect the value of a number, just the characters in a string. Numbers in CSS are f32. The vast majority of f32s can be represented in 16MM characters, but it’s possible to author a document that contains a set of numeric characters longer than 16MM code points. These scenarios are considered undefined behaviour.

§Value Data for Kind::Hash

If the Kind is Kind::Hash, Value Data represents the length of that hash (this means the parser is restricted from representing IDs and hex codes longer than 16,777,216 characters which is probably an acceptable limit). Note that this restriction means that ID selectors have a much tigher limit than other tokens, such as strings or idents, but it’s very unlikely to see a 16million character ID in CSS (String, maybe).

§Value Data for Kind::Url

If the Kind is Kind::Url, Value Data represents the “leading length” and “trailing length” of the URL. This means the value data is split into two 12 bit numbers:

|--------------|--------------|
| LL           | TL           |
| 000000000000 | 000000000000 |
|--------------|--------------|
| 12---------- | 12---------- |

The “leading” length represents the url( part of the token. Typically this will be 4, however it’s possible (for legacy compatibility reasons within CSS) to add whitespace between the opening parenthesis and the URL value. It’s also possible to escape the url ident portion. This means \75\52\6c( is also a valid leading section of a URL ident (which has a character length of 13), as is \000075 \000052 \00006c ( (28 characters). 12 bits allows for a maximum character length of 4,096. It is not possible to represent a URL token’s leading section using 4,096 characters so there is some headroom (wasted bytes) here.

The “trailing” length represents the ) part of the token. Typically this will be 1, however it’s possible to add any number of whitespace characters between the end of the URL and the closing parenthesis. If a CSS document contains more than 4095 whitespace characters then this is considered undefined behaviour.

§Value Data for Kind::Dimension

If K is a Dimension, then this represents both the number of characters in the numeric portion of the dimension and the length of the ident portion of the dimension… or the dimension unit itself (more on that below). This means the value data is split into two 12 bit numbers:

|--------------|--------------|
| NL           | DUL          |
| 000000000000 | 000000000000 |
|--------------|--------------|
| 12---------- | 12---------- |

The NL portion - the numeric length - represents the length of characters the number contains. This means the numeric portion of a dimension can only be 4,096 characters long. This is dramatically shorter than the 16MM allowed for numbers but it’s still also incredibly generous such that it’s highly unlikely to ever be hit unless someone is intentionally trying to break the parser. The Lexer encountering a dimension with a numeric portion longer than 4,096 characters is considered undefined behaviour.

The DUL portion (if TF & 100 == 0) will represent the length of characters the ident portion of the dimension (aka the dimension unit) contains. This means the ident portion of a dimension can only be 4,096 characters long. For practical purposes CSS has a fixed set of dimensions - the longest of which (at the time of writing) are 5 characters long (e.g. svmax). Through the use of escaping shenanigans it’s possible to create a valid CSS dimension longer than 5 characters though (every ident can be made 8 times longer by using escape characters, e.g. 1svmax at 6 characters can be instead written as 1\000073 \000076 \00006d \000061 \000078 at 40 characters). In addition to these factors, it’s worth pointing out that there is scope for further dimensions and some proposals for “custom” dimensions, and lastly this library is designed for CSS and CSS-alike languages, which may invent their own dimension units. In other words being too restrictive on dimension ident length could be costly in the future, therefore 4,096 characters seems like a reasonable, if generous, trade-off.

There’s a giant caveat here though, and a carve out for parsing CSS as it exists today. If TF & 100 != 0, then the dimension is considered “known” and DUL will be encoded differently. Instead of being the dimension unit length, which requires consulting the underlying &str to get the actual dimension, it will be used to store the DimensionUnit - an enum of known CSS dimensions. In this mode Token::dimension_unit() will return a valid DimensionUnit (excluding DimensionUnit::Unknown). When it comes to reasoning about dimensions from the outside, this won’t make a significant difference but it does provide a nice performance boost in parser implementations without slowing down the Lexer by any significant amount. However, if a dimension unit is escaped in any way it will not be represented as a known DimensionUnit, due to the variability in the length encoding which would otherwise be lost if using the enum variant.

§Value

The Value portion of Token represents the length of the token for most token kinds. However, for some tokens their length is already packed into the first u32. So it would make more sense to use this u32 to store more interesting data.

§Value for Kind::Delim and single character tokens

Kind::Delim and single-character tokens (i.e. Kind::Colon->Kind::RightCurly) typically have a length of 1 (Kind::Delim can have a varied length for surrogate pairs). Instead of storing the length and wasting a whole u32, this region stores the char. Calling Token::char() will return an Option which will always be Some for Kind::Delim and single-character tokens.

§Value for Kind::Hash

The length of a hash is stored in its VD portion, leaving 32bits to storing other data. It just so happens that a 8-character hex code (#ffaabbcc) fits nicely inside of 32-bits. During tokenization we can eagerly parse the hex code and stuff it here, so it can be more easily reasoned about in upstream code (rather than reading the character data).

§Value for Kind::Number and Kind::Dimension

As these tokens store their length data in the VD portion, this u32 instead stores the value of the number, stored as f32::to_bits().

§Value data for other tokens.

In all other cases, this represents the length of the token as utf-8 bytes. This means the token length is 4,294,967,296 aka ~4GB. This sounds very long but also CSS can host very large image data and browsers will accomodate very large URLs. An mdn article on Data URLs claims that Firefox supports 32mb Data URLs, Chrome supports over 512mb, and Safari over 2gb. The reality is that if someone has such a large data URL in their CSS they probably should split it out, but we have a whole 32 bits to store the length so we may as well use it…


  1. Dimensions do not have a bool returning method for whether or not the dimension is known, instead Token::dimension_unit() == DimensionUnit::Unknown can be consulted. 

  2. Strings do not have a bool returning method for whether or not the quote is using double or single quotes, instead the Token::quote_style() method will returning the QuoteStyle enum for better readability. 

  3. Whitespace tokens to not have a bool returning method, instead Token::whitespace_style() will return the Whitespace enum for improved readability. 

  4. Delims can be used in interesting ways inside of CSS syntax. At higher levels CSS is sometimes whitespace sensitive, for example the whitespace inside of a CSS selector sometimes represents the descendant combinator, meanwhile delimiters inside calc() are sensitive to whitespace collapse (calc(1px + 1px) is valid while calc(1px+1px) is a parse error). Further to this, introducing whitespace (say through a formatter) might break in interesting ways due to some combinations of Delims & Idents - for example Pseudo Classes like :hover, or CSS like languages such as SASS using $var style syntax. While :hover and $var are comprised of two tokens they’re considered one conceptual unit. Having a way to express these relationships at the token level can be useful for other low level machinery such as formatters/minifiers, rather than introducing complex state at higher levels. For these reasons, Delim tokens have the ability to express their whitespace association. The lexer will always produce a token with empty whitespace rules, but parsers can replace this token with a more complex set of rules. 

  5. Rather than using the 3 bits as a bit-mask, Comment tokens use the data to store the CommentStyle enum, which is capable of representing 8 discrete comment styles. 

Implementations§

Source§

impl Token

Source

pub const EMPTY: Token

Represents an empty token.

Source

pub const EOF: Token

Represents an EOF token.

Source

pub const CDO: Token

Represents a CDO (<!--) token.

Source

pub const CDC: Token

Represents a CDC (-->) token.

Source

pub const SPACE: Token

Represents a single ’ ’ space token.

Source

pub const TAB: Token

Represents a single Tab token.

Source

pub const NEWLINE: Token

Represents a single \n token.

Source

pub const NUMBER_ZERO: Token

Represents the Number 0. This is not equal to other representations of zero, such as 00, 0e0, 0.0 and so on.

Source

pub const COLON: Token

Represents the : token.

Source

pub const SEMICOLON: Token

Represents the ; token.

Source

pub const COMMA: Token

Represents the , token.

Source

pub const LEFT_SQUARE: Token

Represents the [ token.

Source

pub const RIGHT_SQUARE: Token

Represents the ] token.

Source

pub const LEFT_PAREN: Token

Represents the ( token.

Source

pub const RIGHT_PAREN: Token

Represents the ) token.

Source

pub const LEFT_CURLY: Token

Represents the { token.

Source

pub const RIGHT_CURLY: Token

Represents the } token.

Source

pub const BANG: Token

Represents a ! Kind::Delim token.

Source

pub const HASH: Token

Represents a # Kind::Delim token.

Source

pub const DOLLAR: Token

Represents a $ Kind::Delim token.

Source

pub const PERCENT: Token

Represents a % Kind::Delim token - not to be confused with the % dimension.

Source

pub const AMPERSAND: Token

Represents a & Kind::Delim token.

Source

pub const ASTERISK: Token

Represents a * Kind::Delim token.

Source

pub const PLUS: Token

Represents a + Kind::Delim token.

Source

pub const DASH: Token

Represents a - Kind::Delim token.

Source

pub const PERIOD: Token

Represents a . Kind::Delim token.

Source

pub const SLASH: Token

Represents a / Kind::Delim token.

Source

pub const LESS_THAN: Token

Represents a < Kind::Delim token.

Source

pub const EQUALS: Token

Represents a = Kind::Delim token.

Source

pub const GREATER_THAN: Token

Represents a > Kind::Delim token.

Source

pub const QUESTION: Token

Represents a ? Kind::Delim token.

Source

pub const AT: Token

Represents a @ Kind::Delim token. Not to be confused with the @keyword token.

Source

pub const BACKSLASH: Token

Represents a \\ Kind::Delim token.

Source

pub const CARET: Token

Represents a ^ Kind::Delim token.

Source

pub const UNDERSCORE: Token

Represents a _ Kind::Delim token.

Source

pub const BACKTICK: Token

Represents a ``` Kind::Delim token.

Source

pub const PIPE: Token

Represents a | Kind::Delim token.

Source

pub const TILDE: Token

Represents a ~ Kind::Delim token.

Source

pub const REPLACEMENT_CHARACTER: Token

Represents a replacement character Kind::Delim token.

Source

pub const fn dummy(kind: Kind) -> Self

Creates a “Dummy” token with no additional data, just the Kind.

Source

pub const fn dummy_ident() -> Self

Creates a “Dummy” token with no additional data, just Kind::Ident.

Source

pub const fn kind(&self) -> Kind

Returns the Kind.

Source

pub const fn is_empty(&self) -> bool

The only token with an empty length is EOF, but this method is available for symmetry with len().

Source

pub const fn len(&self) -> u32

Returns the amount of characters (utf-8 code points) this Token represents in the underlying source text.

Source

pub const fn char(&self) -> Option<char>

If the Kind is “Delim Like” (i.e. it is Kind::Delim, Kind::Colon, Kind::Semicolon, Kind::Comma, Kind::LeftSquare, Kind::RightSquare, Kind::LeftParen, Kind::RightParen, Kind::LeftCurly, Kind::RightCurly) then this will return a Some with a char representing the value. For non-delim-like tokens this will return None.

Source

pub const fn is_int(&self) -> bool

The Token is a Kind::Dimension or Kind::Number and is an integer - i.e. it has no ..

Source

pub const fn is_float(&self) -> bool

The Token is a Kind::Dimension or Kind::Number and is a float - i.e. it has decimal places. This will be true even if the decimal places are 0. e.g. 0.0.

Source

pub const fn has_sign(&self) -> bool

The Token is a Kind::Dimension or Kind::Number and the underlying character data included a - or + character. Note that a positive number may not necessarily have a sign, e.g. 3 will return false, while +3 will return true.

Source

pub const fn numeric_len(&self) -> u32

If the Token is a Kind::Dimension or Kind::Number then this returns the amount of characters used to represent this number in the underlying source text. Numbers may be inefficiently encoded in the source text, e.g. 0.0000.

Asserts: the kind() is Kind::Dimension or Kind::Number.

Source

pub fn value(&self) -> f32

If the Token is a Kind::Dimension or Kind::Number then this returns the f32 representation of the number’s value.

Asserts: the kind() is Kind::Dimension or Kind::Number.

Source

pub fn whitespace_style(&self) -> Whitespace

Returns the Whitespace.

If the Token is not a Kind::Whitespace this will return Whitespace::none().

Source

pub fn associated_whitespace(&self) -> AssociatedWhitespaceRules

Returns the AssociatedWhitespaceRules.

If the Kind is not “Delim Like” (i.e. it is not Kind::Delim, Kind::Colon, Kind::Semicolon, Kind::Comma, Kind::LeftSquare, Kind::RightSquare, Kind::LeftParen, Kind::RightParen, Kind::LeftCurly, Kind::RightCurly) then this will always return AssociatedWhitespaceRules::none().

Source

pub fn with_associated_whitespace( &self, rules: AssociatedWhitespaceRules, ) -> Token

Returns a new Token with the AssociatedWhitespaceRules set to the given AssociatedWhitespaceRules, if possible.

If the Kind is not “Delim Like” (i.e. it is not Kind::Delim, Kind::Colon, Kind::Semicolon, Kind::Comma, Kind::LeftSquare, Kind::RightSquare, Kind::LeftParen, Kind::RightParen, Kind::LeftCurly, Kind::RightCurly) then this will return the same Token. If the AssociatedWhitespaceRules is different it will return a new Token.

Source

pub fn comment_style(&self) -> Option<CommentStyle>

Returns the CommentStyle.

If the Token is not a Kind::Comment this will return None.

Source

pub const fn dimension_unit(&self) -> DimensionUnit

Returns the DimensionUnit.

If the Token is not a Kind::Dimension this will return DimensionUnit::Unknown. If the Token is a Kind::Dimension, but the dimension unit is custom (e.g. dashed), has escape characters, or is not a recognised CSS Dimension, this will return DimensionUnit::Unknown.

Source

pub fn quote_style(&self) -> QuoteStyle

Returns the QuoteStyle.

If the Token is not a Kind::String this will return QuoteStyle::None.

Source

pub fn with_quotes(&self, quote_style: QuoteStyle) -> Token

Returns a new Token with the QuoteStyle set to the given QuoteStyle, if possible.

If the Token is not a Kind::String, or the QuoteStyle is already the given QuoteStyle this will return the same Token. If the QuoteStyle is different it will return a new Token. QuoteStyle must not be QuoteStyle::None

Source

pub const fn has_close_quote(&self) -> bool

If the Token is a Kind::String this checks if the string ended in a close quote. It is possible to have a valid String token that does not end in a close quote, by eliding the quote at the end of a file.

Asserts: The Kind is Kind::String.

Source

pub const fn can_escape(&self) -> bool

Checks if it is possible for the Token to contain escape characters. Numbers, for example, cannot. Idents can.

Source

pub const fn contains_escape_chars(&self) -> bool

If the Token can escape, checks if the underlying source text contained escape characters.

Asserts: The token can escape (Token::can_escape()).

Source

pub const fn is_dashed_ident(&self) -> bool

If the Token is Ident like, checks if the first two code points are HYPHEN-MINUS (-).

Asserts: The token is “ident like”, i.e. it is Kind::Ident, Kind::AtKeyword, Kind::Function, Kind::Hash.

Source

pub const fn is_lower_case(&self) -> bool

Checks if the Token is Ident like and none of the characters are ASCII upper-case.

Source

pub const fn is_trivia(&self) -> bool

Checks if the Token is Trivia-like, that is Kind::Comment, Kind::Whitespace, Kind::Eof

Source

pub const fn url_has_leading_space(&self) -> bool

If the Token is Kind::Url, checks if there are leading Whitespace characters before the inner value.

Asserts: The token is Kind::Url.

Source

pub const fn url_has_closing_paren(&self) -> bool

If the Token is Kind::Url, checks if the closing parenthesis is present.

Asserts: The token is Kind::Url.

Source

pub const fn hash_is_id_like(&self) -> bool

If the Token is Kind::Hash, checks if the Hash is “ID-like” (i.e its first character is ASCII).

Asserts: The token is Kind::Hash.

Source

pub const fn is_bad(&self) -> bool

Checks if the Token is Kind::BadString or Kind::BadUrl.

Source

pub const fn is_cdc(&self) -> bool

Checks if the Token is Kind::CdcOrCdo and is the CDC variant of that token.

Source

pub fn leading_len(&self) -> u32

Some tokens may have a “leading” part:

This function returns the length of that, irrespective of the Kind. For other kinds not listed, this will return 0, but for the above kinds it will calculate the leading length. This is useful for parsing out the underlying data which is likely to be of greater use.

Source

pub fn trailing_len(&self) -> u32

Some tokens may have a “trailing” part:

This function returns the length of that, irrespective of the Kind. For other kinds not listed, this will return 0, but for the above kinds it will calculate the leading length. This is useful for parsing out the underlying data which is likely to be of greater use.

Source

pub fn to_pairwise(&self) -> Option<PairWise>

Certain kinds have a PairWise equivalent:

This function returns the PairWise enum, if the Token is one of the above listed Kinds. For any other Kind this returns None.

Source

pub fn with_cursor(self, offset: SourceOffset) -> Cursor

A convenience function for Cursor::new(offset, token).

Source

pub fn hex_value(self) -> u32

If the Kind is Kind::Hash then this token may have had the opportunity to be parsed as a <hex-value> (e.g. #fff). When this happens the character data is parsed during tokenization into a u32 which stores the RR,GG,BB,AA values.

Source

pub fn needs_separator_for(&self, second: Token) -> bool

If this Token is preceded by the Token other then a separating token (e.g. a comment) will need to be inserted between these the two tokens during serialization, in order for them to be able to be re-tokenized as the same tokens. For example an Ident (“a”) adjacent to an Ident (“b”), if serialized without whitespace, would create a single Ident (“ab”). The rules for estbalishing whether or not these tokens needs whitespace are quite simple and are effectively defined in the serialization section of the spec. To reproduce the table:

identfunctionurlbad url-numberpercentagedimensionCDC(*%
ident
at-keyword
hash
dimension
#
-
number
@
.
+
/

The one exception not in this table is that two consecutive / characters should also be separated by spaces in order to avoid abmiguities with CSS-alike languages that treat two consecutive / characters as a single line comment.

§Example
use css_lexer::*;
let mut lexer = Lexer::new("10 %");
let first = lexer.advance();
let _ = lexer.advance(); // Whitespace
let second = lexer.advance();
assert!(first.needs_separator_for(second));

Trait Implementations§

Source§

impl Clone for Token

Source§

fn clone(&self) -> Token

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 Debug for Token

Source§

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

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

impl Default for Token

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Token

Source§

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

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

impl From<Cursor> for Token

Source§

fn from(cursor: Cursor) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for DimensionUnit

Source§

fn from(token: Token) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for Kind

Source§

fn from(token: Token) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for KindSet

Source§

fn from(token: Token) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for QuoteStyle

Source§

fn from(token: Token) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for Whitespace

Source§

fn from(token: Token) -> Self

Converts to this type from the input type.
Source§

impl Hash for Token

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Token

Source§

fn cmp(&self, other: &Token) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<AssociatedWhitespaceRules> for Token

Source§

fn eq(&self, other: &AssociatedWhitespaceRules) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<CommentStyle> for Token

Source§

fn eq(&self, other: &CommentStyle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<DimensionUnit> for Token

Source§

fn eq(&self, other: &DimensionUnit) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Kind> for Token

Source§

fn eq(&self, other: &Kind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<KindSet> for Token

Source§

fn eq(&self, other: &KindSet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<PairWise> for Token

Source§

fn eq(&self, other: &PairWise) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<QuoteStyle> for Token

Source§

fn eq(&self, other: &QuoteStyle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Token> for Cursor

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Whitespace> for Token

Source§

fn eq(&self, other: &Whitespace) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<char> for Token

Source§

fn eq(&self, other: &char) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Token

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Token

Source§

fn partial_cmp(&self, other: &Token) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Token

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Token

Source§

impl Eq for Token

Source§

impl StructuralPartialEq for Token

Auto Trait Implementations§

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Send for Token

§

impl Sync for Token

§

impl Unpin for Token

§

impl UnwindSafe for Token

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<D> OwoColorize for D

§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either [OwoColorize::fg] or a color-specific method, such as [OwoColorize::green], Read more
§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either [OwoColorize::bg] or a color-specific method, such as [OwoColorize::on_yellow], Read more
§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

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

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.