pub struct Scalar<E>
where E: Environment,
{ /* private fields */ }

Implementations§

§

impl<E> Scalar<E>
where E: Environment,

pub fn from_field_lossy(field: &Field<E>) -> Scalar<E>

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,

pub const SIZE_IN_BITS: usize = <E::Scalar>::SIZE_IN_BITS

The scalar size in bits.

pub const SIZE_IN_BYTES: usize = _

The scalar size in bytes.

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>

Initializes a new scalar.

Trait Implementations§

§

impl<E> Add<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn add(self, other: &Scalar<E>) -> <Scalar<E> as Add<&Scalar<E>>>::Output

Returns the sum of self and other.

§

type Output = Scalar<E>

The resulting type after applying the + operator.
§

impl<E> Add for Scalar<E>
where E: Environment,

§

fn add(self, other: Scalar<E>) -> <Scalar<E> as Add>::Output

Returns the sum of self and other.

§

type Output = Scalar<E>

The resulting type after applying the + operator.
§

impl<E> AddAssign<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn add_assign(&mut self, other: &Scalar<E>)

Adds other to self.

§

impl<E> AddAssign for Scalar<E>
where E: Environment,

§

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,

§

fn clone(&self) -> Scalar<E>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl<E> Compare for Scalar<E>
where E: Environment,

§

fn is_less_than(&self, other: &Scalar<E>) -> <Scalar<E> as Compare>::Output

Returns true if self is less than other.

§

fn is_greater_than(&self, other: &Scalar<E>) -> <Scalar<E> as Compare>::Output

Returns true if self is greater than other.

§

fn is_less_than_or_equal( &self, other: &Scalar<E> ) -> <Scalar<E> as Compare>::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>::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,

§

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

Formats the value using the given formatter. Read more
§

impl<E> Deref for Scalar<E>
where E: Environment,

§

type Target = <E as Environment>::Scalar

The resulting type after dereferencing.
§

fn deref(&self) -> &<Scalar<E> as Deref>::Target

Dereferences the value.
§

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>,

Deserializes the scalar from a string or bytes.

§

impl<E> Display for Scalar<E>
where E: Environment,

§

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

Formats the value using the given formatter. Read more
§

impl<E> Distribution<Scalar<E>> for Standard
where E: Environment,

§

fn sample<R>(&self, rng: &mut R) -> Scalar<E>
where R: Rng + ?Sized,

Generate a random value of T, using rng as the source of randomness.
source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
§

impl<E> Div<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn div(self, other: &Scalar<E>) -> <Scalar<E> as Div<&Scalar<E>>>::Output

Returns the quotient of self and other.

§

type Output = Scalar<E>

The resulting type after applying the / operator.
§

impl<E> Div for Scalar<E>
where E: Environment,

§

fn div(self, other: Scalar<E>) -> <Scalar<E> as Div>::Output

Returns the quotient of self and other.

§

type Output = Scalar<E>

The resulting type after applying the / operator.
§

impl<E> DivAssign<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn div_assign(&mut self, other: &Scalar<E>)

Divides self by other.

§

impl<E> DivAssign for Scalar<E>
where E: Environment,

§

fn div_assign(&mut self, other: Scalar<E>)

Divides self by other.

§

impl<E> Double for Scalar<E>
where E: Environment,

§

fn double(&self) -> <Scalar<E> as Double>::Output

Returns the double of self.

§

type Output = Scalar<E>

§

impl<E> Equal for Scalar<E>
where E: Environment,

§

fn is_equal(&self, other: &Scalar<E>) -> <Scalar<E> as Equal>::Output

Returns true if self and other are equal.

§

fn is_not_equal(&self, other: &Scalar<E>) -> <Scalar<E> as Equal>::Output

Returns true if self and other are not equal.

§

type Output = Boolean<E>

§

impl<E> FromBits for Scalar<E>
where E: Environment,

§

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 than E::Scalar::size_in_bits(), the excess bits are enforced to be 0s.
  • If bits_le is shorter than E::Scalar::size_in_bits(), it is padded with 0s up to scalar size.
§

fn from_bits_be(bits_be: &[bool]) -> Result<Scalar<E>, Error>

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

§

impl<E> FromBytes for Scalar<E>
where E: Environment,

§

fn read_le<R>(reader: R) -> Result<Scalar<E>, Error>
where R: Read,

Reads the scalar from a buffer.

source§

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

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

impl<E> FromField for Scalar<E>
where E: Environment,

§

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:

  1. If the field element is larger than the scalar field modulus, then the operation will fail.
  2. 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 between size_in_data_bits < bits.len() < size_in_bits.
§

type Field = Field<E>

§

impl<E> FromStr for Scalar<E>
where E: Environment,

§

fn from_str(string: &str) -> Result<Scalar<E>, Error>

Parses a string into a scalar.

§

type Err = Error

The associated error which can be returned from parsing.
§

impl<E> Hash for Scalar<E>
where E: Hash + Environment, <E as Environment>::Scalar: Hash,

§

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<E> Inverse for Scalar<E>
where E: Environment,

§

fn inverse(&self) -> Result<<Scalar<E> as Inverse>::Output, Error>

Returns the inverse of self.

§

type Output = Scalar<E>

§

impl<E> Mul<&Group<E>> for Scalar<E>
where E: Environment,

§

fn mul(self, other: &Group<E>) -> <Scalar<E> as Mul<&Group<E>>>::Output

Returns the product of self and other.

§

type Output = Group<E>

The resulting type after applying the * operator.
§

impl<E> Mul<&Scalar<E>> for Group<E>
where E: Environment,

§

fn mul(self, other: &Scalar<E>) -> <Group<E> as Mul<&Scalar<E>>>::Output

Returns the product of self and other.

§

type Output = Group<E>

The resulting type after applying the * operator.
§

impl<E> Mul<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn mul(self, other: &Scalar<E>) -> <Scalar<E> as Mul<&Scalar<E>>>::Output

Returns the product of self and other.

§

type Output = Scalar<E>

The resulting type after applying the * operator.
§

impl<E> Mul<Group<E>> for Scalar<E>
where E: Environment,

§

fn mul(self, other: Group<E>) -> <Scalar<E> as Mul<Group<E>>>::Output

Returns the product of self and other.

§

type Output = Group<E>

The resulting type after applying the * operator.
§

impl<E> Mul<Scalar<E>> for Group<E>
where E: Environment,

§

fn mul(self, other: Scalar<E>) -> <Group<E> as Mul<Scalar<E>>>::Output

Returns the product of self and other.

§

type Output = Group<E>

The resulting type after applying the * operator.
§

impl<E> Mul for Scalar<E>
where E: Environment,

§

fn mul(self, other: Scalar<E>) -> <Scalar<E> as Mul>::Output

Returns the product of self and other.

§

type Output = Scalar<E>

The resulting type after applying the * operator.
§

impl<E> MulAssign<&Scalar<E>> for Group<E>
where E: Environment,

§

fn mul_assign(&mut self, other: &Scalar<E>)

Multiplies self by other.

§

impl<E> MulAssign<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn mul_assign(&mut self, other: &Scalar<E>)

Multiplies self by other.

§

impl<E> MulAssign<Scalar<E>> for Group<E>
where E: Environment,

§

fn mul_assign(&mut self, other: Scalar<E>)

Multiplies self by other.

§

impl<E> MulAssign for Scalar<E>
where E: Environment,

§

fn mul_assign(&mut self, other: Scalar<E>)

Multiplies self by other.

§

impl<E> Neg for Scalar<E>
where E: Environment,

§

fn neg(self) -> <Scalar<E> as Neg>::Output

Returns the negation of self.

§

type Output = Scalar<E>

The resulting type after applying the - operator.
§

impl<E> One for Scalar<E>
where E: Environment,

§

fn one() -> Scalar<E>

Returns the 1 element of the scalar.

§

fn is_one(&self) -> bool

Returns true if the element is one.

source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
§

impl<E> Ord for Scalar<E>
where E: Environment,

§

fn cmp(&self, other: &Scalar<E>) -> Ordering

Returns the lexicographic ordering of self and other.

1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
§

impl<E> Parser for Scalar<E>
where E: Environment,

§

fn parse(string: &str) -> Result<(&str, Scalar<E>), Err<VerboseError<&str>>>

Parses a string into a scalar circuit.

§

impl<E> PartialEq for Scalar<E>

§

fn eq(&self, other: &Scalar<E>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl<E> PartialOrd for Scalar<E>
where E: Environment,

§

fn partial_cmp(&self, other: &Scalar<E>) -> Option<Ordering>

Returns the lexicographic ordering of self and other.

1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<E> Pow<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn pow(self, other: &Scalar<E>) -> <Scalar<E> as Pow<&Scalar<E>>>::Output

Returns the power of self to the power of other.

§

type Output = Scalar<E>

The result after applying the operator.
§

impl<E> Pow<Scalar<E>> for Scalar<E>
where E: Environment,

§

fn pow(self, other: Scalar<E>) -> <Scalar<E> as Pow<Scalar<E>>>::Output

Returns the power of self to the power of other.

§

type Output = Scalar<E>

The result after applying the operator.
§

impl<'a, E> Product<&'a Scalar<E>> for Scalar<E>
where E: Environment,

§

fn product<I>(iter: I) -> Scalar<E>
where I: Iterator<Item = &'a Scalar<E>>,

Returns the product of self and other.

§

impl<E> Product for Scalar<E>
where E: Environment,

§

fn product<I>(iter: I) -> Scalar<E>
where I: Iterator<Item = Scalar<E>>,

Returns the product of self and other.

§

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,

Serializes the scalar into a string or as bytes.

§

impl<E> SizeInBits for Scalar<E>
where E: Environment,

§

fn size_in_bits() -> usize

Returns the scalar size in bits.

§

impl<E> SizeInBytes for Scalar<E>
where E: Environment,

§

fn size_in_bytes() -> usize

Returns the scalar size in bytes.

§

impl<E> SizeInDataBits for Scalar<E>
where E: Environment,

§

fn size_in_data_bits() -> usize

Returns the scalar capacity for data bits.

§

impl<E> Square for Scalar<E>
where E: Environment,

§

fn square(&self) -> <Scalar<E> as Square>::Output

Returns the square of self.

§

type Output = Scalar<E>

§

impl<E> Sub<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn sub(self, other: &Scalar<E>) -> <Scalar<E> as Sub<&Scalar<E>>>::Output

Returns the difference of self and other.

§

type Output = Scalar<E>

The resulting type after applying the - operator.
§

impl<E> Sub for Scalar<E>
where E: Environment,

§

fn sub(self, other: Scalar<E>) -> <Scalar<E> as Sub>::Output

Returns the difference of self and other.

§

type Output = Scalar<E>

The resulting type after applying the - operator.
§

impl<E> SubAssign<&Scalar<E>> for Scalar<E>
where E: Environment,

§

fn sub_assign(&mut self, other: &Scalar<E>)

Subtracts other from self.

§

impl<E> SubAssign for Scalar<E>
where E: Environment,

§

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,

§

fn sum<I>(iter: I) -> Scalar<E>
where I: Iterator<Item = &'a Scalar<E>>,

Returns the sum of self and other.

§

impl<E> Sum for Scalar<E>
where E: Environment,

§

fn sum<I>(iter: I) -> Scalar<E>
where I: Iterator<Item = Scalar<E>>,

Returns the sum of self and other.

§

impl<E> Ternary for Scalar<E>
where E: Environment,

§

fn ternary( condition: &<Scalar<E> as Ternary>::Boolean, first: &Scalar<E>, second: &Scalar<E> ) -> <Scalar<E> as Ternary>::Output

Returns first if condition is true, otherwise returns second.

§

type Boolean = Boolean<E>

§

type Output = Scalar<E>

§

impl<E> ToBits for Scalar<E>
where E: Environment,

§

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

Outputs the little-endian bit representation of self without trailing zeros.

§

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

Outputs the big-endian bit representation of self without leading zeros.

source§

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

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

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

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

fn num_bits() -> Option<usize>

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

impl<E> ToBytes for Scalar<E>
where E: Environment,

§

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

Writes the scalar to a buffer.

source§

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

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

impl<E> ToField for Scalar<E>
where E: Environment,

§

fn to_field(&self) -> Result<<Scalar<E> as ToField>::Field, Error>

Returns the scalar as a field element.

§

type Field = Field<E>

§

impl<E> TypeName for Scalar<E>
where E: Environment,

§

fn type_name() -> &'static str

Returns the type name as a string.

§

impl<E> Zero for Scalar<E>
where E: Environment,

§

fn zero() -> Scalar<E>

Returns the 0 element of the scalar.

§

fn is_zero(&self) -> bool

Returns true if the element is zero.

source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
§

impl<E> Zeroize for Scalar<E>
where E: Environment,

§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
§

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> StructuralPartialEq for Scalar<E>
where E: Environment,

Auto Trait Implementations§

§

impl<E> RefUnwindSafe for Scalar<E>

§

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> 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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

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

source§

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

Checks if this value is equivalent to the given key. Read more
§

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.

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.

§

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
source§

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

§

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§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
source§

impl<T> Uniform for T

source§

fn rand<R>(rng: &mut R) -> T
where R: Rng + ?Sized,

Samples a random value from a uniform distribution.
§

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

§

fn vzip(self) -> V

source§

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