Struct snarkvm_console_program::Scalar
pub struct Scalar<E>where
E: Environment,{ /* private fields */ }
Implementations§
§impl<E> Scalar<E>where
E: Environment,
impl<E> Scalar<E>where E: Environment,
pub fn from_field_lossy(field: &Field<E>) -> Result<Scalar<E>, Error>
pub fn from_field_lossy(field: &Field<E>) -> Result<Scalar<E>, Error>
Casts a scalar from a base field, with lossy truncation.
This method is commonly-used by hash-to-scalar algorithms, where the hash output does not need to preserve the full base field.
§impl<E> Scalar<E>where
E: Environment,
impl<E> Scalar<E>where E: Environment,
pub const SIZE_IN_BITS: usize = <E::Scalar>::SIZE_IN_BITS
pub const SIZE_IN_BITS: usize = <E::Scalar>::SIZE_IN_BITS
The scalar size in bits.
pub const SIZE_IN_BYTES: usize = (<E::Scalar>::SIZE_IN_BITS + 7) / 8
pub const SIZE_IN_BYTES: usize = (<E::Scalar>::SIZE_IN_BITS + 7) / 8
The scalar size in bytes.
pub const SIZE_IN_DATA_BITS: usize = <E::Scalar>::SIZE_IN_DATA_BITS
pub const SIZE_IN_DATA_BITS: usize = <E::Scalar>::SIZE_IN_DATA_BITS
The scalar capacity for data bits.
pub const fn new(scalar: <E as Environment>::Scalar) -> Scalar<E>
pub const fn new(scalar: <E as Environment>::Scalar) -> Scalar<E>
Initializes a new scalar.
Trait Implementations§
§impl<E> Add<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Add<&Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Add<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Add<Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> AddAssign<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> AddAssign<&Scalar<E>> for Scalar<E>where E: Environment,
§fn add_assign(&mut self, other: &Scalar<E>)
fn add_assign(&mut self, other: &Scalar<E>)
Adds other
to self
.
§impl<E> AddAssign<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> AddAssign<Scalar<E>> for Scalar<E>where E: Environment,
§fn add_assign(&mut self, other: Scalar<E>)
fn add_assign(&mut self, other: Scalar<E>)
Adds other
to self
.
§impl<E> Clone for Scalar<E>where
E: Clone + Environment,
<E as Environment>::Scalar: Clone,
impl<E> Clone for Scalar<E>where E: Clone + Environment, <E as Environment>::Scalar: Clone,
§impl<E> Compare<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Compare<Scalar<E>> for Scalar<E>where E: Environment,
§fn is_less_than(
&self,
other: &Scalar<E>
) -> <Scalar<E> as Compare<Scalar<E>>>::Output
fn is_less_than( &self, other: &Scalar<E> ) -> <Scalar<E> as Compare<Scalar<E>>>::Output
Returns true
if self
is less than other
.
§fn is_greater_than(
&self,
other: &Scalar<E>
) -> <Scalar<E> as Compare<Scalar<E>>>::Output
fn is_greater_than( &self, other: &Scalar<E> ) -> <Scalar<E> as Compare<Scalar<E>>>::Output
Returns true
if self
is greater than other
.
§fn is_less_than_or_equal(
&self,
other: &Scalar<E>
) -> <Scalar<E> as Compare<Scalar<E>>>::Output
fn is_less_than_or_equal( &self, other: &Scalar<E> ) -> <Scalar<E> as Compare<Scalar<E>>>::Output
Returns true
if self
is less than or equal to other
.
§fn is_greater_than_or_equal(
&self,
other: &Scalar<E>
) -> <Scalar<E> as Compare<Scalar<E>>>::Output
fn is_greater_than_or_equal( &self, other: &Scalar<E> ) -> <Scalar<E> as Compare<Scalar<E>>>::Output
Returns true
if self
is greater than or equal to other
.
type Output = Boolean<E>
§impl<E> Debug for Scalar<E>where
E: Environment,
impl<E> Debug for Scalar<E>where E: Environment,
§impl<E> Deref for Scalar<E>where
E: Environment,
impl<E> Deref for Scalar<E>where E: Environment,
§impl<'de, E> Deserialize<'de> for Scalar<E>where
E: Environment,
impl<'de, E> Deserialize<'de> for Scalar<E>where E: Environment,
§fn deserialize<D>(
deserializer: D
) -> Result<Scalar<E>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Scalar<E>, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
Deserializes the scalar from a string or bytes.
§impl<E> Display for Scalar<E>where
E: Environment,
impl<E> Display for Scalar<E>where E: Environment,
§impl<E> Distribution<Scalar<E>> for Standardwhere
E: Environment,
impl<E> Distribution<Scalar<E>> for Standardwhere E: Environment,
§fn sample<R>(&self, rng: &mut R) -> Scalar<E>where
R: Rng + ?Sized,
fn sample<R>(&self, rng: &mut R) -> Scalar<E>where R: Rng + ?Sized,
T
, using rng
as the source of randomness.§impl<E> Div<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Div<&Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Div<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Div<Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> DivAssign<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> DivAssign<&Scalar<E>> for Scalar<E>where E: Environment,
§fn div_assign(&mut self, other: &Scalar<E>)
fn div_assign(&mut self, other: &Scalar<E>)
Divides self
by other
.
§impl<E> DivAssign<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> DivAssign<Scalar<E>> for Scalar<E>where E: Environment,
§fn div_assign(&mut self, other: Scalar<E>)
fn div_assign(&mut self, other: Scalar<E>)
Divides self
by other
.
§impl<E> Double for Scalar<E>where
E: Environment,
impl<E> Double for Scalar<E>where E: Environment,
§impl<E> Equal<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Equal<Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> FromBits for Scalar<E>where
E: Environment,
impl<E> FromBits for Scalar<E>where E: Environment,
§fn from_bits_le(bits_le: &[bool]) -> Result<Scalar<E>, Error>
fn from_bits_le(bits_le: &[bool]) -> Result<Scalar<E>, Error>
Initializes a new scalar from a list of little-endian bits.
- If
bits_le
is longer thanE::Scalar::size_in_bits()
, the excess bits are enforced to be0
s. - If
bits_le
is shorter thanE::Scalar::size_in_bits()
, it is padded with0
s up to scalar size.
§impl<E> FromBytes for Scalar<E>where
E: Environment,
impl<E> FromBytes for Scalar<E>where E: Environment,
§impl<E> FromField for Scalar<E>where
E: Environment,
impl<E> FromField for Scalar<E>where E: Environment,
§fn from_field(
field: &<Scalar<E> as FromField>::Field
) -> Result<Scalar<E>, Error>
fn from_field( field: &<Scalar<E> as FromField>::Field ) -> Result<Scalar<E>, Error>
Casts a scalar from a base field element.
This method guarantees the following:
- If the field element is larger than the scalar field modulus, then the operation will fail.
- If the field element is smaller than the scalar field modulus, then the operation will succeed.
- This is particularly useful for the case where a user called,
Scalar::from_field(scalar.to_field())
, and the scalar bit representation is betweensize_in_data_bits < bits.len() < size_in_bits
.
type Field = Field<E>
§impl<E> FromStr for Scalar<E>where
E: Environment,
impl<E> FromStr for Scalar<E>where E: Environment,
§impl<E> Hash for Scalar<E>where
E: Hash + Environment,
<E as Environment>::Scalar: Hash,
impl<E> Hash for Scalar<E>where E: Hash + Environment, <E as Environment>::Scalar: Hash,
§impl<E> Inverse for Scalar<E>where
E: Environment,
impl<E> Inverse for Scalar<E>where E: Environment,
§impl<E> Mul<&Group<E>> for Scalar<E>where
E: Environment,
impl<E> Mul<&Group<E>> for Scalar<E>where E: Environment,
§impl<E> Mul<&Scalar<E>> for Group<E>where
E: Environment,
impl<E> Mul<&Scalar<E>> for Group<E>where E: Environment,
§impl<E> Mul<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Mul<&Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Mul<Group<E>> for Scalar<E>where
E: Environment,
impl<E> Mul<Group<E>> for Scalar<E>where E: Environment,
§impl<E> Mul<Scalar<E>> for Group<E>where
E: Environment,
impl<E> Mul<Scalar<E>> for Group<E>where E: Environment,
§impl<E> Mul<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Mul<Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> MulAssign<&Scalar<E>> for Group<E>where
E: Environment,
impl<E> MulAssign<&Scalar<E>> for Group<E>where E: Environment,
§fn mul_assign(&mut self, other: &Scalar<E>)
fn mul_assign(&mut self, other: &Scalar<E>)
Multiplies self
by other
.
§impl<E> MulAssign<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> MulAssign<&Scalar<E>> for Scalar<E>where E: Environment,
§fn mul_assign(&mut self, other: &Scalar<E>)
fn mul_assign(&mut self, other: &Scalar<E>)
Multiplies self
by other
.
§impl<E> MulAssign<Scalar<E>> for Group<E>where
E: Environment,
impl<E> MulAssign<Scalar<E>> for Group<E>where E: Environment,
§fn mul_assign(&mut self, other: Scalar<E>)
fn mul_assign(&mut self, other: Scalar<E>)
Multiplies self
by other
.
§impl<E> MulAssign<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> MulAssign<Scalar<E>> for Scalar<E>where E: Environment,
§fn mul_assign(&mut self, other: Scalar<E>)
fn mul_assign(&mut self, other: Scalar<E>)
Multiplies self
by other
.
§impl<E> Neg for Scalar<E>where
E: Environment,
impl<E> Neg for Scalar<E>where E: Environment,
§impl<E> One for Scalar<E>where
E: Environment,
impl<E> One for Scalar<E>where E: Environment,
§impl<E> Ord for Scalar<E>where
E: Environment,
impl<E> Ord for Scalar<E>where E: Environment,
§impl<E> Parser for Scalar<E>where
E: Environment,
impl<E> Parser for Scalar<E>where E: Environment,
§impl<E> PartialEq<Scalar<E>> for Scalar<E>where
E: PartialEq<E> + Environment,
<E as Environment>::Scalar: PartialEq<<E as Environment>::Scalar>,
impl<E> PartialEq<Scalar<E>> for Scalar<E>where E: PartialEq<E> + Environment, <E as Environment>::Scalar: PartialEq<<E as Environment>::Scalar>,
§impl<E> PartialOrd<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> PartialOrd<Scalar<E>> for Scalar<E>where E: Environment,
§fn partial_cmp(&self, other: &Scalar<E>) -> Option<Ordering>
fn partial_cmp(&self, other: &Scalar<E>) -> Option<Ordering>
Returns the lexicographic ordering of self
and other
.
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl<E> Pow<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Pow<&Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Pow<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Pow<Scalar<E>> for Scalar<E>where E: Environment,
§impl<'a, E> Product<&'a Scalar<E>> for Scalar<E>where
E: Environment,
impl<'a, E> Product<&'a Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Product<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Product<Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Serialize for Scalar<E>where
E: Environment,
impl<E> Serialize for Scalar<E>where E: Environment,
§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
Serializes the scalar into a string or as bytes.
§impl<E> SizeInBits for Scalar<E>where
E: Environment,
impl<E> SizeInBits for Scalar<E>where E: Environment,
§fn size_in_bits() -> usize
fn size_in_bits() -> usize
Returns the scalar size in bits.
§impl<E> SizeInBytes for Scalar<E>where
E: Environment,
impl<E> SizeInBytes for Scalar<E>where E: Environment,
§fn size_in_bytes() -> usize
fn size_in_bytes() -> usize
Returns the scalar size in bytes.
§impl<E> SizeInDataBits for Scalar<E>where
E: Environment,
impl<E> SizeInDataBits for Scalar<E>where E: Environment,
§fn size_in_data_bits() -> usize
fn size_in_data_bits() -> usize
Returns the scalar capacity for data bits.
§impl<E> Square for Scalar<E>where
E: Environment,
impl<E> Square for Scalar<E>where E: Environment,
§impl<E> Sub<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Sub<&Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Sub<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Sub<Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> SubAssign<&Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> SubAssign<&Scalar<E>> for Scalar<E>where E: Environment,
§fn sub_assign(&mut self, other: &Scalar<E>)
fn sub_assign(&mut self, other: &Scalar<E>)
Subtracts other
from self
.
§impl<E> SubAssign<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> SubAssign<Scalar<E>> for Scalar<E>where E: Environment,
§fn sub_assign(&mut self, other: Scalar<E>)
fn sub_assign(&mut self, other: Scalar<E>)
Subtracts other
from self
.
§impl<'a, E> Sum<&'a Scalar<E>> for Scalar<E>where
E: Environment,
impl<'a, E> Sum<&'a Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Sum<Scalar<E>> for Scalar<E>where
E: Environment,
impl<E> Sum<Scalar<E>> for Scalar<E>where E: Environment,
§impl<E> Ternary for Scalar<E>where
E: Environment,
impl<E> Ternary for Scalar<E>where E: Environment,
§impl<E> ToBits for Scalar<E>where
E: Environment,
impl<E> ToBits for Scalar<E>where E: Environment,
§fn to_bits_le(&self) -> Vec<bool, Global>
fn to_bits_le(&self) -> Vec<bool, Global>
Outputs the little-endian bit representation of self
without trailing zeros.
§fn to_bits_be(&self) -> Vec<bool, Global>
fn to_bits_be(&self) -> Vec<bool, Global>
Outputs the big-endian bit representation of self
without leading zeros.
§impl<E> ToBytes for Scalar<E>where
E: Environment,
impl<E> ToBytes for Scalar<E>where E: Environment,
§impl<E> ToField for Scalar<E>where
E: Environment,
impl<E> ToField for Scalar<E>where E: Environment,
§impl<E> TypeName for Scalar<E>where
E: Environment,
impl<E> TypeName for Scalar<E>where E: Environment,
§impl<E> Zero for Scalar<E>where
E: Environment,
impl<E> Zero for Scalar<E>where E: Environment,
impl<E> Copy for Scalar<E>where E: Copy + Environment, <E as Environment>::Scalar: Copy,
impl<E> Eq for Scalar<E>where E: Eq + Environment, <E as Environment>::Scalar: Eq,
impl<E> GroupTrait<Scalar<E>> for Group<E>where E: Environment,
impl<E> ScalarTrait for Scalar<E>where E: Environment,
impl<E> StructuralEq for Scalar<E>where E: Environment,
impl<E> StructuralPartialEq for Scalar<E>where E: Environment,
Auto Trait Implementations§
impl<E> RefUnwindSafe for Scalar<E>where <E as Environment>::Scalar: RefUnwindSafe,
impl<E> Send for Scalar<E>
impl<E> Sync for Scalar<E>
impl<E> Unpin for Scalar<E>where <E as Environment>::Scalar: Unpin,
impl<E> UnwindSafe for Scalar<E>where <E as Environment>::Scalar: 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<'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 Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.