pub struct Value {
pub id: Option<GlobalId>,
pub(crate) contents: ValueVariants,
}
Fields§
§id: Option<GlobalId>
§contents: ValueVariants
Implementations§
Source§impl Value
impl Value
Sourcepub fn eq(&self, rhs: &Self) -> Result<bool>
pub fn eq(&self, rhs: &Self) -> Result<bool>
Are the values equal, according to SnarkVM?
We use this rather than the Eq trait so we can fail when comparing values of different types, rather than just returning false.
Sourcepub fn resolve_if_unsuffixed(
&self,
ty: &Option<Type>,
span: Span,
) -> Result<Value>
pub fn resolve_if_unsuffixed( &self, ty: &Option<Type>, span: Span, ) -> Result<Value>
Resolves an unsuffixed literal to a typed Value
using the provided optional Type
. If the value is unsuffixed
and a type is provided, parses the string into the corresponding Value
variant. Handles integers of various
widths and special types like Field
, Group
, and Scalar
. If no type is given or the value is already typed,
returns the original value. Returns an error if type inference is not possible or parsing fails.
Source§impl Value
impl Value
pub fn lt(&self, rhs: &Self) -> Option<bool>
pub fn lte(&self, rhs: &Self) -> Option<bool>
pub fn gt(&self, rhs: &Self) -> Option<bool>
pub fn gte(&self, rhs: &Self) -> Option<bool>
pub fn inc_wrapping(&self) -> Option<Self>
pub fn add(&self, i: usize) -> Option<Self>
pub fn cast(&self, ty: &Type) -> Option<Self>
pub fn cast_lossy(&self, ty: &LiteralType) -> Option<Self>
pub fn as_u32(&self) -> Option<u32>
pub fn as_i128(&self) -> Option<i128>
pub fn array_index(&self, i: usize) -> Option<Self>
pub fn array_index_set(&mut self, i: usize, value: Self) -> Option<()>
pub fn tuple_len(&self) -> Option<usize>
pub fn tuple_index(&self, i: usize) -> Option<Self>
pub fn tuple_index_set(&mut self, i: usize, value: Self) -> Option<()>
pub fn as_future(&self) -> Option<&[AsyncExecution]>
pub fn accesses( &self, accesses: impl IntoIterator<Item = Access<TestnetV0>>, ) -> Option<Value>
fn accesses_impl( &self, accesses: &mut dyn Iterator<Item = Access<TestnetV0>>, ) -> Option<Value>
pub fn member_access(&self, member: Symbol) -> Option<Self>
pub fn member_set(&mut self, member: Symbol, value: Value) -> Option<()>
pub fn make_future( program_name: Symbol, function: Symbol, arguments: impl IntoIterator<Item = Value>, ) -> Option<Value>
fn make_future_impl( program_name: Symbol, function: Symbol, arguments: &mut dyn Iterator<Item = Value>, ) -> Option<Value>
pub fn make_unit() -> Self
pub fn make_struct( contents: impl Iterator<Item = (Symbol, Value)>, program: Symbol, path: Vec<Symbol>, ) -> Self
pub fn make_record( contents: impl Iterator<Item = (Symbol, Value)>, program: Symbol, path: Vec<Symbol>, ) -> Self
pub fn make_array(contents: impl Iterator<Item = Value>) -> Self
pub fn make_tuple(contents: impl IntoIterator<Item = Value>) -> Self
Sourcepub fn get_numeric_type(&self) -> Option<Type>
pub fn get_numeric_type(&self) -> Option<Type>
Gets the type of a Value
but only if it is an integer, a field, a group, or a scalar.
Return None
otherwise. These are the only types that an unsuffixed literal can have.
pub fn to_expression( &self, span: Span, node_builder: &NodeBuilder, ty: &Type, struct_lookup: &dyn Fn(&[Symbol]) -> Vec<(Symbol, Type)>, ) -> Option<Expression>
Trait Implementations§
Source§impl From<ValueVariants> for Value
impl From<ValueVariants> for Value
Source§fn from(contents: ValueVariants) -> Self
fn from(contents: ValueVariants) -> Self
Source§impl From<Vec<AsyncExecution>> for Value
impl From<Vec<AsyncExecution>> for Value
Source§fn from(x: Vec<AsyncExecution>) -> Self
fn from(x: Vec<AsyncExecution>) -> Self
impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl !Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
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<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.