Module transform

Module transform 

Source
Expand description

This module contains the transforming parsers. This are the parsers that add, remove, replace or reorder Tokens while parsing.

Note: When the proc_macro2 feature is disabled, IntoIdent<T> is not available because it requires parsing from strings (&str.into_token_iter()) which is only available with proc_macro2.

Structs§

Discard
Succeeds when the next token matches T. The token will be removed from the stream but not stored. Consequently the ToTokens implementations will panic with a message that it can not be emitted. This can only be used when a token should be present but not stored and never emitted.
Insert
Injects tokens without parsing anything.
IntoIdent
Parses T and concats all its elements to a single identifier by removing all characters that are not valid in identifiers. When T implements Default, such as single string (non group) keywords, operators and Const* literals. Then it can be used to create IntoIdentifier on the fly. Note that construction may still fail when one tries to create a invalid identifier such as one starting with digits for example.
IntoLiteralString
Parses T and creates a LiteralString from it. When T implements Default, such as single string (non group) keywords, operators and Const* literals. It can be used to create IntoLiteralString on the fly.
IntoTokenStream
Parses T and keeps it as opaque TokenStream. This is useful when one wants to parse a sequence of tokens and keep it as opaque unit or re-parse it later as something else.
Skip
Skips over expected tokens. Will parse and consume the tokens but not store them. Consequently the ToTokens implementations will not output any tokens.
Swap
Swaps the order of two entities.

Type Aliases§

AsDefault
Parse a T and replace it with its default value. This is a zero sized type. It can be used for no allocation replacement elements in a Vec since it has a optimization for zero-sized-types where it wont allocate any memory but just act as counter then.
OrDefault
Tries to parse a T or inserts a D when that fails.
Replace
Parse-skip a T and inserts a U: Default in place. This is a zero sized type.
TokenStreamUntil
Parses a TokenStream until, but excluding T. The presence of T is mandatory.