Crate proc_macro
A support library for macro authors when defining new macros.
This library, provided by the standard distribution, provides the types
consumed in the interfaces of procedurally defined macro definitions such as
function-like macros #[proc_macro], macro attributes #[proc_macro_attribute] and
custom derive attributes #[proc_macro_derive].
See the book for more.
Modules
-
bridge
Internal interface for communicating between a
proc_macroclient (a proc macro crate) and aproc_macroserver (a compiler front-end). - diagnostic
- escape
-
quote
Quasiquoter
This file contains the implementation internals of the quasiquoter provided by
quote!. This quasiquoter uses macros 2.0 hygiene to reliably access items fromproc_macro, to build aproc_macro::TokenStream. - to_tokens
-
token_stream
Public implementation details for the
TokenStreamtype, such as iterators. - tracked Functionality for adding environment state to the build dependency info.
Structs
-
ConcatStreamsHelper
Non-generic helper for implementing
FromIterator<TokenStream>andExtend<TokenStream>with less monomorphization in calling crates. -
ConcatTreesHelper
Non-generic helper for implementing
FromIterator<TokenTree>andExtend<TokenTree>with less monomorphization in calling crates. - Diagnostic A structure representing a diagnostic message and associated children messages.
-
ExpandError
Error returned from
TokenStream::expand_expr. - Group A delimited token stream.
- HasIterator
-
Ident
An identifier (
ident). -
LexError
Error returned from
TokenStream::from_str. -
Literal
A literal string (
"hello"), byte string (b"hello"), C string (c"hello"), character ('a'), byte character (b'a'), an integer or floating point number with or without a suffix (1,1u8,2.3,2.3f32). Boolean literals liketrueandfalsedo not belong here, they areIdents. -
Punct
A
Punctis a single punctuation character such as+,-or#. - RepInterp
- Span A region of source code, along with macro expansion information.
- ThereIsNoIteratorInRepetition
- TokenStream The main type provided by this crate, representing an abstract stream of tokens, or, more specifically, a sequence of token trees. The type provides interfaces for iterating over those token trees and, conversely, collecting a number of token trees into one stream.
Enums
- Base
- ConversionErrorKind Errors returned when trying to retrieve a literal unescaped value.
- Delimiter Describes how a sequence of token trees is delimited.
- EscapeError Mostly relating to malformed escape sequences, but also a few other problems.
- Level An enum representing a diagnostic level.
-
Spacing
Indicates whether a
Puncttoken can join with the following token to form a multi-character operator. -
TokenTree
A single token or a delimited sequence of token trees (e.g.,
[1, (), ..]).
Traits
Functions
- is_available Determines whether proc_macro has been made accessible to the currently running program.
- parse_number
-
quote
Quote a
TokenStreaminto aTokenStream. This is the actual implementation of thequote!()proc macro. -
quote_span
Quote a
Spaninto aTokenStream. This is needed to implement a custom quoter. - strip_underscores
- tree_to_bridge_tree
Macros
- diagnostic_method
- extend_items
- float_values
- integer_values
-
quote
quote!(..)accepts arbitrary tokens and expands into aTokenStreamdescribing the input. For example,quote!(a + b)will produce an expression, that, when evaluated, constructs theTokenStream[Ident("a"), Punct('+', Alone), Ident("b")]. - suffixed_int_literals
- unsuffixed_int_literals