Enum SvmLiteralParam

pub(crate) enum SvmLiteralParam<N>
where N: Network,
{
Show 17 variants Address(Address<N>), Boolean(Boolean<N>), Field(Field<N>), Group(Group<N>), I8(Integer<N, i8>), I16(Integer<N, i16>), I32(Integer<N, i32>), I64(Integer<N, i64>), I128(Integer<N, i128>), U8(Integer<N, u8>), U16(Integer<N, u16>), U32(Integer<N, u32>), U64(Integer<N, u64>), U128(Integer<N, u128>), Scalar(Scalar<N>), Signature(Box<Signature<N>>), String(StringType<N>),
}
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(Integer<N, i8>)

The 8-bit signed integer type.

§

I16(Integer<N, i16>)

The 16-bit signed integer type.

§

I32(Integer<N, i32>)

The 32-bit signed integer type.

§

I64(Integer<N, i64>)

The 64-bit signed integer type.

§

I128(Integer<N, i128>)

The 128-bit signed integer type.

§

U8(Integer<N, u8>)

The 8-bit unsigned integer type.

§

U16(Integer<N, u16>)

The 16-bit unsigned integer type.

§

U32(Integer<N, u32>)

The 32-bit unsigned integer type.

§

U64(Integer<N, u64>)

The 64-bit unsigned integer type.

§

U128(Integer<N, u128>)

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§

§

impl<N> Literal<N>
where N: Network,

pub fn cast(&self, to_type: LiteralType) -> Result<Literal<N>, Error>

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.

§

impl<N> Literal<N>
where N: Network,

pub fn cast_lossy(&self, to_type: LiteralType) -> Result<Literal<N>, Error>

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.

§

impl<N> Literal<N>
where N: Network,

pub fn from_bits_le(variant: u8, bits_le: &[bool]) -> Result<Literal<N>, Error>

Initializes a new literal from a list of little-endian bits without trailing zeros.

pub fn from_bits_be(variant: u8, bits_be: &[bool]) -> Result<Literal<N>, Error>

Initializes a new literal from a list of big-endian bits without leading zeros.

§

impl<N> Literal<N>
where N: Network,

pub fn sample<R>(literal_type: LiteralType, rng: &mut R) -> Literal<N>
where R: Rng + CryptoRng,

Returns a randomly-sampled literal of the given literal type.

§

impl<N> Literal<N>
where N: Network,

pub fn size_in_bits(&self) -> u16

Returns the number of bits of this literal.

§

impl<N> Literal<N>
where N: Network,

pub fn size_in_bytes(&self) -> u16

Returns the size in bytes of this literal.

§

impl<N> Literal<N>
where N: Network,

pub fn to_type(&self) -> LiteralType

Returns the type name of the literal.

§

impl<N> Literal<N>
where N: Network,

pub fn variant(&self) -> u8

Returns the variant of the literal.

Trait Implementations§

§

impl<N> Clone for Literal<N>
where N: Clone + Network,

§

fn clone(&self) -> Literal<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<N> Debug for Literal<N>
where N: Network,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'de, N> Deserialize<'de> for Literal<N>
where N: Network,

§

fn deserialize<D>( deserializer: D, ) -> Result<Literal<N>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserializes the literal from a string or bytes.

§

impl<N> Display for Literal<N>
where N: Network,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<N> Equal for Literal<N>
where N: Network,

§

fn is_equal(&self, other: &Literal<N>) -> <Literal<N> as Equal>::Output

Returns true if self and other are equal.

§

fn is_not_equal(&self, other: &Literal<N>) -> <Literal<N> as Equal>::Output

Returns true if self and other are not equal.

§

type Output = Boolean<N>

§

impl<N> From<&Literal<N>> for Plaintext<N>
where N: Network,

§

fn from(literal: &Literal<N>) -> Plaintext<N>

Returns a new Plaintext from a &Literal.

§

impl<N> From<&Literal<N>> for Value<N>
where N: Network,

§

fn from(literal: &Literal<N>) -> Value<N>

Initializes the value from a literal.

§

impl<N> From<Address<N>> for Literal<N>
where N: Network,

§

fn from(value: Address<N>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Boolean<N>> for Literal<N>
where N: Network,

§

fn from(value: Boolean<N>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Field<N>> for Literal<N>
where N: Network,

§

fn from(value: Field<N>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Group<N>> for Literal<N>
where N: Network,

§

fn from(value: Group<N>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, i128>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, i128>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, i16>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, i16>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, i32>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, i32>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, i64>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, i64>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, i8>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, i8>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, u128>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, u128>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, u16>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, u16>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, u32>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, u32>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, u64>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, u64>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Integer<N, u8>> for Literal<N>
where N: Network,

§

fn from(value: Integer<N, u8>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Literal<N>> for Plaintext<N>
where N: Network,

§

fn from(literal: Literal<N>) -> Plaintext<N>

Returns a new Plaintext from a Literal.

§

impl<N> From<Literal<N>> for Value<N>
where N: Network,

§

fn from(literal: Literal<N>) -> Value<N>

Initializes the value from a literal.

Source§

impl From<Literal<TestnetV0>> for Value

Source§

fn from(x: Literal<TestnetV0>) -> Self

Converts to this type from the input type.
§

impl<N> From<Scalar<N>> for Literal<N>
where N: Network,

§

fn from(value: Scalar<N>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> From<Signature<N>> for Literal<N>
where N: Network,

§

fn from(value: Signature<N>) -> Literal<N>

Converts to this type from the input type.
§

impl<N> FromBytes for Literal<N>
where N: Network,

§

fn read_le<R>(reader: R) -> Result<Literal<N>, Error>
where R: Read,

Reads the literal from a buffer.

§

fn from_bytes_le(bytes: &[u8]) -> Result<Self, Error>
where Self: Sized,

Returns Self from a byte array in little-endian order.
§

impl<N> FromStr for Literal<N>
where N: Network,

§

fn from_str(string: &str) -> Result<Literal<N>, Error>

Parses a string into a literal.

§

type Err = Error

The associated error which can be returned from parsing.
§

impl<N> Hash for Literal<N>
where N: Network,

§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<N> Parser for Literal<N>
where N: Network,

§

fn parse(string: &str) -> Result<(&str, Literal<N>), Err<VerboseError<&str>>>

Parses a string into a literal.

§

impl<N> PartialEq for Literal<N>
where N: Network,

§

fn eq(&self, other: &Literal<N>) -> bool

Returns true if self and other are equal.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<N> Serialize for Literal<N>
where N: Network,

§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serializes the literal into a string or as bytes.

§

impl<N> ToBits for &Literal<N>
where N: Network,

§

fn write_bits_le(&self, vec: &mut Vec<bool>)

Returns the little-endian bits of the literal.

§

fn write_bits_be(&self, vec: &mut Vec<bool>)

Returns the big-endian bits of the literal.

§

fn to_bits_le(&self) -> Vec<bool>

Returns self as a boolean array in little-endian order.
§

fn to_bits_be(&self) -> Vec<bool>

Returns self as a boolean array in big-endian order.
§

fn num_bits() -> Option<usize>

An optional indication of how many bits an object can be represented with.
§

impl<N> ToBits for Literal<N>
where N: Network,

§

fn write_bits_le(&self, vec: &mut Vec<bool>)

Returns the little-endian bits of the literal.

§

fn write_bits_be(&self, vec: &mut Vec<bool>)

Returns the big-endian bits of the literal.

§

fn to_bits_le(&self) -> Vec<bool>

Returns self as a boolean array in little-endian order.
§

fn to_bits_be(&self) -> Vec<bool>

Returns self as a boolean array in big-endian order.
§

fn num_bits() -> Option<usize>

An optional indication of how many bits an object can be represented with.
§

impl<N> ToBytes for Literal<N>
where N: Network,

§

fn write_le<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

Writes the literal to a buffer.

§

fn to_bytes_le(&self) -> Result<Vec<u8>, Error>
where Self: Sized,

Returns self as a byte array in little-endian order.
Source§

impl TryAsRef<Literal<TestnetV0>> for Value

§

impl<N> Eq for Literal<N>
where N: Network,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<'de, T> DeserializeExt<'de> for T

§

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
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

§

fn to_smolstr(&self) -> SmolStr

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T> ToStringFallible for T
where T: Display,

§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> GraphNode for T
where T: 'static + Clone + Eq + PartialEq + Debug + Hash,