pub enum Type {
Show 19 variants
Address,
Array(ArrayType),
Boolean,
Composite(CompositeType),
Field,
Future(FutureType),
Group,
Identifier(Identifier),
Integer(IntegerType),
Mapping(MappingType),
Optional(OptionalType),
Scalar,
Signature,
String,
Tuple(TupleType),
Vector(VectorType),
Numeric,
Unit,
Err,
}Expand description
Explicit type used for defining a variable or expression type
Variants§
Address
The address type.
Array(ArrayType)
The array type.
Boolean
The bool type.
Composite(CompositeType)
The struct type.
Field
The field type.
Future(FutureType)
The future type.
Group
The group type.
Identifier(Identifier)
A reference to a built in type.
Integer(IntegerType)
An integer type.
Mapping(MappingType)
A mapping type.
Optional(OptionalType)
A nullable type.
Scalar
The scalar type.
Signature
The signature type.
String
The string type.
Tuple(TupleType)
A static tuple of at least one type.
Vector(VectorType)
The vector type.
Numeric
Numeric type which should be resolved to Field, Group, Integer(_), or Scalar.
Unit
The unit type.
Err
Placeholder for a type that could not be resolved or was not well-formed. Will eventually lead to a compile error.
Implementations§
Source§impl Type
impl Type
Sourcepub fn eq_user(&self, other: &Type) -> bool
pub fn eq_user(&self, other: &Type) -> bool
Are the types considered equal as far as the Leo user is concerned?
In particular, any comparison involving an Err is true, and Futures which aren’t explicit compare equal to
other Futures.
An array with an undetermined length (e.g., one that depends on a const) is considered equal to other arrays
if their element types match. This allows const propagation to potentially resolve the length before type
checking is performed again.
Composite types are considered equal if their names and resolved program names match. If either side still has const generic arguments, they are treated as equal unconditionally since monomorphization and other passes of type-checking will handle mismatches later.
Sourcepub fn eq_flat_relaxed(&self, other: &Self) -> bool
pub fn eq_flat_relaxed(&self, other: &Self) -> bool
Returns true if the self Type is equal to the other Type in all aspects besides composite program of origin.
In the case of futures, it also makes sure that if both are not explicit, they are equal.
Flattens array syntax: [[u8; 1]; 2] == [u8; (2, 1)] == true
Composite types are considered equal if their names match. If either side still has const generic arguments, they are treated as equal unconditionally since monomorphization and other passes of type-checking will handle mismatches later.
pub fn from_snarkvm<N: Network>( t: &PlaintextType<N>, program: Option<Symbol>, ) -> Self
pub fn to_snarkvm<N: Network>(&self) -> Result<PlaintextType<N>>
pub fn size_in_bits<N: Network, F>( &self, is_raw: bool, get_structs: F, ) -> Result<usize>
Sourcepub fn can_coerce_to(&self, expected: &Type) -> bool
pub fn can_coerce_to(&self, expected: &Type) -> bool
Determines whether self can be coerced to the expected type.
This method checks if the current type can be implicitly coerced to the expected type according to specific rules:
Optional<T>can be coerced toOptional<T>.Tcan be coerced toOptional<T>.- Arrays
[T; N]can be coerced to[Optional<T>; N]if lengths match or are unknown, and element types are coercible. - Falls back to an equality check for other types.
§Arguments
expected- The type to whichselfis being coerced.
§Returns
true if coercion is allowed; false otherwise.
pub fn is_optional(&self) -> bool
pub fn is_vector(&self) -> bool
pub fn is_mapping(&self) -> bool
pub fn to_optional(&self) -> Type
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Type
impl<'de> Deserialize<'de> for Type
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 From<CompositeType> for Type
impl From<CompositeType> for Type
Source§fn from(value: CompositeType) -> Self
fn from(value: CompositeType) -> Self
Source§impl From<FutureType> for Type
impl From<FutureType> for Type
Source§fn from(value: FutureType) -> Self
fn from(value: FutureType) -> Self
Source§impl From<VectorType> for Type
impl From<VectorType> for Type
Source§fn from(value: VectorType) -> Self
fn from(value: VectorType) -> Self
impl Eq for Type
impl StructuralPartialEq for Type
Auto Trait Implementations§
impl Freeze for Type
impl RefUnwindSafe for Type
impl Send for Type
impl Sync for Type
impl Unpin for Type
impl UnwindSafe for Type
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.