pub enum Expression {
Show 20 variants
ArrayAccess(Box<ArrayAccess>),
AssociatedConstant(AssociatedConstantExpression),
AssociatedFunction(AssociatedFunctionExpression),
Async(AsyncExpression),
Array(ArrayExpression),
Binary(Box<BinaryExpression>),
Call(Box<CallExpression>),
Cast(Box<CastExpression>),
Err(ErrExpression),
Path(Path),
Literal(Literal),
Locator(LocatorExpression),
MemberAccess(Box<MemberAccess>),
Repeat(Box<RepeatExpression>),
Struct(StructExpression),
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].
AssociatedConstant(AssociatedConstantExpression)
An associated constant; e.g., group::GEN.
AssociatedFunction(AssociatedFunctionExpression)
An associated function; e.g., BHP256::hash_to_field.
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.
Call(Box<CallExpression>)
A call expression, e.g., my_fun(args).
Cast(Box<CastExpression>)
A cast expression, e.g., 42u32 as u8.
Err(ErrExpression)
An expression of type “error”. Will result in a compile error eventually.
Path(Path)
A path to some item, e.g., foo::bar::x.
Literal(Literal)
A literal expression.
Locator(LocatorExpression)
A locator expression, e.g., hello.aleo/foo.
MemberAccess(Box<MemberAccess>)
An access of a struct member, e.g. struc.member.
Repeat(Box<RepeatExpression>)
An array expression constructed from one repeated element, e.g., [1u32; 5].
Struct(StructExpression)
An expression constructing a struct like Foo { bar: 42, baz }.
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
pub(crate) fn precedence(&self) -> u32
pub(crate) fn associativity(&self) -> Associativity
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 zero(
ty: &Type,
span: Span,
node_builder: &NodeBuilder,
struct_lookup: &dyn Fn(&[Symbol]) -> Vec<(Symbol, Type)>,
) -> Option<Self>
pub fn zero( ty: &Type, span: Span, node_builder: &NodeBuilder, struct_lookup: &dyn Fn(&[Symbol]) -> 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 struct initialization).
Supported types:
- Integers (
i8–i128,u8–u128): literal0 - Boolean: literal
false - Field, Group, Scalar: zero literals
"0" - Structs: recursively constructs a struct 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 struct_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 · 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<AssociatedConstantExpression> for Expression
impl From<AssociatedConstantExpression> for Expression
Source§fn from(value: AssociatedConstantExpression) -> Self
fn from(value: AssociatedConstantExpression) -> Self
Source§impl From<AssociatedFunctionExpression> for Expression
impl From<AssociatedFunctionExpression> for Expression
Source§fn from(value: AssociatedFunctionExpression) -> Self
fn from(value: AssociatedFunctionExpression) -> 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<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<Literal> for Expression
impl From<Literal> for Expression
Source§impl From<LocatorExpression> for Expression
impl From<LocatorExpression> for Expression
Source§fn from(value: LocatorExpression) -> Self
fn from(value: LocatorExpression) -> Self
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<StructExpression> for Expression
impl From<StructExpression> for Expression
Source§fn from(value: StructExpression) -> Self
fn from(value: StructExpression) -> 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§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 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,
§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>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToSmolStr for T
impl<T> ToSmolStr for T
fn to_smolstr(&self) -> SmolStr
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.