pub enum Literal<N: Network> {
}
Expand description
The literal enum represents all supported types in snarkVM.
Variants§
Address(Address<N>)
The Aleo address type.
Boolean(Boolean<N>)
The boolean type.
Field(Field<N>)
The field type.
Group(Group<N>)
The group type.
I8(I8<N>)
The 8-bit signed integer type.
I16(I16<N>)
The 16-bit signed integer type.
I32(I32<N>)
The 32-bit signed integer type.
I64(I64<N>)
The 64-bit signed integer type.
I128(I128<N>)
The 128-bit signed integer type.
U8(U8<N>)
The 8-bit unsigned integer type.
U16(U16<N>)
The 16-bit unsigned integer type.
U32(U32<N>)
The 32-bit unsigned integer type.
U64(U64<N>)
The 64-bit unsigned integer type.
U128(U128<N>)
The 128-bit unsigned integer type.
Scalar(Scalar<N>)
The scalar type.
Signature(Box<Signature<N>>)
The signature type.
String(StringType<N>)
The string type.
Implementations§
Source§impl<N: Network> Literal<N>
impl<N: Network> Literal<N>
Sourcepub fn cast(&self, to_type: LiteralType) -> Result<Self>
pub fn cast(&self, to_type: LiteralType) -> Result<Self>
Casts the literal to the given literal type.
This method checks that the cast does not lose any bits of information, and returns an error if it does.
The hierarchy of casting is as follows:
- (
Address
,Group
) <->Field
<->Scalar
<->Integer
<->Boolean
Signature
(not supported)String
(not supported)
Note that casting to left along the hierarchy always preserves information.
Source§impl<N: Network> Literal<N>
impl<N: Network> Literal<N>
Sourcepub fn cast_lossy(&self, to_type: LiteralType) -> Result<Self>
pub fn cast_lossy(&self, to_type: LiteralType) -> Result<Self>
Casts the literal to the given literal type, with lossy truncation.
This method makes a best-effort attempt to preserve all bits of information, but it is not guaranteed to do so.
The hierarchy of casting is as follows:
- (
Address
,Group
) <->Field
<->Scalar
<->Integer
<->Boolean
Signature
(not supported)String
(not supported)
Note that casting to left along the hierarchy always preserves information.
Source§impl<N: Network> Literal<N>
impl<N: Network> Literal<N>
Sourcepub fn from_bits_le(variant: u8, bits_le: &[bool]) -> Result<Self>
pub fn from_bits_le(variant: u8, bits_le: &[bool]) -> Result<Self>
Initializes a new literal from a list of little-endian bits without trailing zeros.
Sourcepub fn from_bits_be(variant: u8, bits_be: &[bool]) -> Result<Self>
pub fn from_bits_be(variant: u8, bits_be: &[bool]) -> Result<Self>
Initializes a new literal from a list of big-endian bits without leading zeros.
Source§impl<N: Network> Literal<N>
impl<N: Network> Literal<N>
Sourcepub fn size_in_bits(&self) -> u16
pub fn size_in_bits(&self) -> u16
Returns the number of bits of this literal.
Source§impl<N: Network> Literal<N>
impl<N: Network> Literal<N>
Sourcepub fn size_in_bytes(&self) -> u16
pub fn size_in_bytes(&self) -> u16
Returns the size in bytes of this literal.
Trait Implementations§
Source§impl<'de, N: Network> Deserialize<'de> for Literal<N>
impl<'de, N: Network> Deserialize<'de> for Literal<N>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserializes the literal from a string or bytes.
Source§impl<N: Network> Parser for Literal<N>
impl<N: Network> Parser for Literal<N>
Source§fn parse(string: &str) -> ParserResult<'_, Self>
fn parse(string: &str) -> ParserResult<'_, Self>
Parses a string into a literal.
Source§impl<N: Network> ToBits for &Literal<N>
impl<N: Network> ToBits for &Literal<N>
Source§fn write_bits_le(&self, vec: &mut Vec<bool>)
fn write_bits_le(&self, vec: &mut Vec<bool>)
Returns the little-endian bits of the literal.
Source§fn write_bits_be(&self, vec: &mut Vec<bool>)
fn write_bits_be(&self, vec: &mut Vec<bool>)
Returns the big-endian bits of the literal.
Source§fn to_bits_le(&self) -> Vec<bool>
fn to_bits_le(&self) -> Vec<bool>
self
as a boolean array in little-endian order.Source§fn to_bits_be(&self) -> Vec<bool>
fn to_bits_be(&self) -> Vec<bool>
self
as a boolean array in big-endian order.Source§impl<N: Network> ToBits for Literal<N>
impl<N: Network> ToBits for Literal<N>
Source§fn write_bits_le(&self, vec: &mut Vec<bool>)
fn write_bits_le(&self, vec: &mut Vec<bool>)
Returns the little-endian bits of the literal.
Source§fn write_bits_be(&self, vec: &mut Vec<bool>)
fn write_bits_be(&self, vec: &mut Vec<bool>)
Returns the big-endian bits of the literal.
Source§fn to_bits_le(&self) -> Vec<bool>
fn to_bits_le(&self) -> Vec<bool>
self
as a boolean array in little-endian order.Source§fn to_bits_be(&self) -> Vec<bool>
fn to_bits_be(&self) -> Vec<bool>
self
as a boolean array in big-endian order.impl<N: Network> Eq for Literal<N>
Auto Trait Implementations§
impl<N> Freeze for Literal<N>where
<N as Environment>::Field: Freeze,
<N as Environment>::Projective: Freeze,
<N as Environment>::Scalar: Freeze,
impl<N> RefUnwindSafe for Literal<N>where
<N as Environment>::Field: RefUnwindSafe,
<N as Environment>::Projective: RefUnwindSafe,
<N as Environment>::Scalar: RefUnwindSafe,
N: RefUnwindSafe,
impl<N> Send for Literal<N>
impl<N> Sync for Literal<N>
impl<N> Unpin for Literal<N>where
<N as Environment>::Field: Unpin,
<N as Environment>::Projective: Unpin,
<N as Environment>::Scalar: Unpin,
N: Unpin,
impl<N> UnwindSafe for Literal<N>where
<N as Environment>::Field: UnwindSafe,
<N as Environment>::Projective: UnwindSafe,
<N as Environment>::Scalar: UnwindSafe,
N: UnwindSafe,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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