Struct macro_tools::tokens::protected::Equation
source · pub struct Equation {
pub left: Path,
pub op: Eq,
pub right: TokenStream,
}
Expand description
Represents an equation parsed from a procedural macro input.
This struct models an equation consisting of a left-hand side, an operator,
and a right-hand side. The Equation
is typically constructed during the
parsing process of macro input, where the left
and op
fields are expected
to be syntactically represented by syn::Path
and syn::BinOp
respectively,
indicating the variable and operation involved. The right
field is a
proc_macro2::TokenStream
, which can represent more complex expressions
including, but not limited to, literals, function calls, or further operations.
§Fields
-
left
: The left-hand side of the equation, represented as a path. This could be a variable or a more complex path in the code being processed by the macro. -
op
: The binary operator used in the equation, such as addition, subtraction, multiplication, etc. -
right
: The right-hand side of the equation. Given the potential complexity of expressions on this side, it is represented as aproc_macro2::TokenStream
to accommodate any valid Rust expression.
§Examples
Parsing an equation from macro input:
use macro_tools::exposed::*;
let got : tokens::Equation = syn::parse_quote!( default = 31 );
tree_print!( got );
assert_eq!( code_to_str!( got ), "default = 31".to_string() );
Fields§
§left: Path
The LHS of the equation, represented by a syntactic path.
op: Eq
Equality token.
right: TokenStream
The RHS of the equation, capable of holding complex expressions.
Trait Implementations§
source§impl ToTokens for Equation
impl ToTokens for Equation
source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Auto Trait Implementations§
impl Freeze for Equation
impl RefUnwindSafe for Equation
impl !Send for Equation
impl !Sync for Equation
impl Unpin for Equation
impl UnwindSafe for Equation
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere
T: Spanned + ?Sized,
source§fn span(&self) -> Span
fn span(&self) -> Span
Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.