Enum Expr

Source
pub enum Expr {
Show 17 variants FieldRef { field_name: Ident, field_token: Dollar, }, Value(Expr), MemberAccess { parent: Box<Expr>, member_name: Ident, member_access_token: Dot, }, PathAccess { parent: Box<Expr>, path_segment: Ident, path_access_token: PathSep, }, FunctionCall { function: Box<Expr>, args: Vec<Expr>, }, And(Box<Expr>, Box<Expr>), Or(Box<Expr>, Box<Expr>), Eq(Box<Expr>, Box<Expr>), Ne(Box<Expr>, Box<Expr>), Lt(Box<Expr>, Box<Expr>), Lte(Box<Expr>, Box<Expr>), Gt(Box<Expr>, Box<Expr>), Gte(Box<Expr>, Box<Expr>), Add(Box<Expr>, Box<Expr>), Sub(Box<Expr>, Box<Expr>), Mul(Box<Expr>, Box<Expr>), Div(Box<Expr>, Box<Expr>),
}
Expand description

A parsed expression.

This type represents a parsed expression that can be used to generate code.

§Examples

use cot_codegen::expr::Expr;
use quote::quote;
use syn::parse_quote;

let expr = Expr::parse(quote! { $field == 42 }).unwrap();
assert_eq!(
    expr,
    Expr::Eq(
        Box::new(Expr::FieldRef { field_name: parse_quote!(field), field_token: parse_quote!($)}),
        Box::new(Expr::Value(parse_quote!(42)))
    )
);

Variants§

§

FieldRef

Fields

§field_name: Ident
§field_token: Dollar
§

Value(Expr)

§

MemberAccess

Fields

§parent: Box<Expr>
§member_name: Ident
§member_access_token: Dot
§

PathAccess

Fields

§parent: Box<Expr>
§path_segment: Ident
§path_access_token: PathSep
§

FunctionCall

Fields

§function: Box<Expr>
§args: Vec<Expr>
§

And(Box<Expr>, Box<Expr>)

§

Or(Box<Expr>, Box<Expr>)

§

Eq(Box<Expr>, Box<Expr>)

§

Ne(Box<Expr>, Box<Expr>)

§

Lt(Box<Expr>, Box<Expr>)

§

Lte(Box<Expr>, Box<Expr>)

§

Gt(Box<Expr>, Box<Expr>)

§

Gte(Box<Expr>, Box<Expr>)

§

Add(Box<Expr>, Box<Expr>)

§

Sub(Box<Expr>, Box<Expr>)

§

Mul(Box<Expr>, Box<Expr>)

§

Div(Box<Expr>, Box<Expr>)

Implementations§

Source§

impl Expr

Source

pub fn parse(input: TokenStream) -> Result<Self>

Parse an Expr from the given token stream.

§Errors

Returns an error if the input is not a valid expression.

Source

pub fn as_tokens(&self) -> Option<TokenStream>

Source

pub fn as_tokens_full(&self) -> TokenStream

Trait Implementations§

Source§

impl Debug for Expr

Source§

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

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

impl Parse for Expr

Source§

fn parse(input: ParseStream<'_>) -> Result<Self>

Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> 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 Eq for Expr

Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl !Send for Expr

§

impl !Sync for Expr

§

impl Unpin for Expr

§

impl UnwindSafe for Expr

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