pub enum Expression {
Show 19 variants
ArrayAccess(Box<ArrayAccess>),
Async(AsyncExpression),
Array(ArrayExpression),
Binary(Box<BinaryExpression>),
Intrinsic(Box<IntrinsicExpression>),
Call(Box<CallExpression>),
DynamicOp(Box<DynamicOpExpression>),
Cast(Box<CastExpression>),
Composite(CompositeExpression),
Err(ErrExpression),
Path(Path),
Literal(Literal),
MemberAccess(Box<MemberAccess>),
Repeat(Box<RepeatExpression>),
Ternary(Box<TernaryExpression>),
Tuple(TupleExpression),
TupleAccess(Box<TupleAccess>),
Unary(Box<UnaryExpression>),
Unit(UnitExpression),
}Expand description
Expression that evaluates to a value.
Variants§
ArrayAccess(Box<ArrayAccess>)
An array access, e.g. arr[i].
Async(AsyncExpression)
An async block: e.g. async { my_mapping.set(1, 2); }.
Array(ArrayExpression)
An array expression, e.g., [true, false, true, false].
Binary(Box<BinaryExpression>)
A binary expression, e.g., 42 + 24.
Intrinsic(Box<IntrinsicExpression>)
An intrinsic expression, e.g., _my_intrinsic(args).
Call(Box<CallExpression>)
A call expression, e.g., my_fun(args).
DynamicOp(Box<DynamicOpExpression>)
A dynamic operation against an interface, e.g., MyInterface @ (target) :: foobar(args),
MyInterface @ (target) :: counter, or MyInterface @ (target) :: entries.get(i).
Cast(Box<CastExpression>)
A cast expression, e.g., 42u32 as u8.
Composite(CompositeExpression)
An expression of type “error”.
Will result in a compile error eventually.
An expression constructing a composite like Foo { bar: 42, baz }.
Err(ErrExpression)
Path(Path)
A path to some item, e.g., foo::bar::x.
Literal(Literal)
A literal expression.
MemberAccess(Box<MemberAccess>)
An access of a composite member, e.g. composite.member.
Repeat(Box<RepeatExpression>)
An array expression constructed from one repeated element, e.g., [1u32; 5].
Ternary(Box<TernaryExpression>)
A ternary conditional expression cond ? if_expr : else_expr.
Tuple(TupleExpression)
A tuple expression e.g., (foo, 42, true).
TupleAccess(Box<TupleAccess>)
A tuple access expression e.g., foo.2.
Unary(Box<UnaryExpression>)
An unary expression.
Unit(UnitExpression)
A unit expression e.g. ()
Implementations§
Source§impl Expression
impl Expression
Sourcepub fn as_u32(&self) -> Option<u32>
pub fn as_u32(&self) -> Option<u32>
Returns self as a known u32 if possible. Otherwise, returns a None. This allows for large and/or signed
types but only if they can be safely cast to a u32.
pub fn is_none_expr(&self) -> bool
Sourcepub fn is_pure(&self, get_type: &impl Fn(NodeID) -> Type) -> bool
pub fn is_pure(&self, get_type: &impl Fn(NodeID) -> Type) -> bool
Returns true if we can confidently say evaluating this expression has no side effects, false otherwise
Sourcepub fn zero(
ty: &Type,
span: Span,
node_builder: &NodeBuilder,
composite_lookup: &dyn Fn(&Location) -> Vec<(Symbol, Type)>,
) -> Option<Self>
pub fn zero( ty: &Type, span: Span, node_builder: &NodeBuilder, composite_lookup: &dyn Fn(&Location) -> Vec<(Symbol, Type)>, ) -> Option<Self>
Returns the zero value expression for a given type, if one exists.
This is used during lowering and reconstruction to provide default or
placeholder values (e.g., for get_or_use calls or composite initialization).
Supported types:
- Integers (
i8–i128,u8–u128): literal0 - Boolean: literal
false - Field, Group, Scalar: zero literals
"0" - Composites: recursively constructs a composite with all members zeroed
- Arrays: repeats a zero element for the array length
Returns None if the type has no well-defined zero representation
(e.g. mapping, Future).
The composite_lookup callback provides member definitions for composite types.
Trait Implementations§
Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl Default for Expression
impl Default for Expression
Source§impl<'de> Deserialize<'de> for Expression
impl<'de> Deserialize<'de> for Expression
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Expression
impl Display for Expression
Source§impl From<ArrayAccess> for Expression
impl From<ArrayAccess> for Expression
Source§fn from(value: ArrayAccess) -> Self
fn from(value: ArrayAccess) -> Self
Source§impl From<ArrayExpression> for Expression
impl From<ArrayExpression> for Expression
Source§fn from(value: ArrayExpression) -> Self
fn from(value: ArrayExpression) -> Self
Source§impl From<AsyncExpression> for Expression
impl From<AsyncExpression> for Expression
Source§fn from(value: AsyncExpression) -> Self
fn from(value: AsyncExpression) -> Self
Source§impl From<BinaryExpression> for Expression
impl From<BinaryExpression> for Expression
Source§fn from(value: BinaryExpression) -> Self
fn from(value: BinaryExpression) -> Self
Source§impl From<CallExpression> for Expression
impl From<CallExpression> for Expression
Source§fn from(value: CallExpression) -> Self
fn from(value: CallExpression) -> Self
Source§impl From<CastExpression> for Expression
impl From<CastExpression> for Expression
Source§fn from(value: CastExpression) -> Self
fn from(value: CastExpression) -> Self
Source§impl From<CompositeExpression> for Expression
impl From<CompositeExpression> for Expression
Source§fn from(value: CompositeExpression) -> Self
fn from(value: CompositeExpression) -> Self
Source§impl From<DynamicOpExpression> for Expression
impl From<DynamicOpExpression> for Expression
Source§fn from(value: DynamicOpExpression) -> Self
fn from(value: DynamicOpExpression) -> Self
Source§impl From<ErrExpression> for Expression
impl From<ErrExpression> for Expression
Source§fn from(value: ErrExpression) -> Self
fn from(value: ErrExpression) -> Self
Source§impl From<Identifier> for Expression
impl From<Identifier> for Expression
Source§fn from(value: Identifier) -> Self
fn from(value: Identifier) -> Self
Source§impl From<IntrinsicExpression> for Expression
impl From<IntrinsicExpression> for Expression
Source§fn from(value: IntrinsicExpression) -> Self
fn from(value: IntrinsicExpression) -> Self
Source§impl From<Literal> for Expression
impl From<Literal> for Expression
Source§impl From<MemberAccess> for Expression
impl From<MemberAccess> for Expression
Source§fn from(value: MemberAccess) -> Self
fn from(value: MemberAccess) -> Self
Source§impl From<Path> for Expression
impl From<Path> for Expression
Source§impl From<RepeatExpression> for Expression
impl From<RepeatExpression> for Expression
Source§fn from(value: RepeatExpression) -> Self
fn from(value: RepeatExpression) -> Self
Source§impl From<TernaryExpression> for Expression
impl From<TernaryExpression> for Expression
Source§fn from(value: TernaryExpression) -> Self
fn from(value: TernaryExpression) -> Self
Source§impl From<TupleAccess> for Expression
impl From<TupleAccess> for Expression
Source§fn from(value: TupleAccess) -> Self
fn from(value: TupleAccess) -> Self
Source§impl From<TupleExpression> for Expression
impl From<TupleExpression> for Expression
Source§fn from(value: TupleExpression) -> Self
fn from(value: TupleExpression) -> Self
Source§impl From<UnaryExpression> for Expression
impl From<UnaryExpression> for Expression
Source§fn from(value: UnaryExpression) -> Self
fn from(value: UnaryExpression) -> Self
Source§impl From<UnitExpression> for Expression
impl From<UnitExpression> for Expression
Source§fn from(value: UnitExpression) -> Self
fn from(value: UnitExpression) -> Self
Source§impl Node for Expression
impl Node for Expression
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§fn eq(&self, other: &Expression) -> bool
fn eq(&self, other: &Expression) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for Expression
impl Serialize for Expression
impl Eq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnsafeUnpin for Expression
impl UnwindSafe for Expression
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
fn take_from_value<D>(
value: &mut Value,
field: &str,
) -> Result<T, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);