pub struct FieldElement { /* private fields */ }

Implementations§

source§

impl FieldElement

source

pub const ZERO: FieldElement = FieldElement::from_mont([0, 0, 0, 0])

FieldElement constant that’s equal to 0

source

pub const ONE: FieldElement = FieldElement::from_mont([18446744073709551585, 18446744073709551615, 18446744073709551615, 576460752303422960])

FieldElement constant that’s equal to 1

source

pub const TWO: FieldElement = FieldElement::from_mont([18446744073709551553, 18446744073709551615, 18446744073709551615, 576460752303422416])

FieldElement constant that’s equal to 2

source

pub const THREE: FieldElement = FieldElement::from_mont([18446744073709551521, 18446744073709551615, 18446744073709551615, 576460752303421872])

FieldElement constant that’s equal to 3

source

pub const MAX: FieldElement = FieldElement::from_mont([32, 0, 0, 544])

Maximum value of FieldElement. Equals to 2^251 + 17 * 2^192.

source

pub const fn from_mont(data: [u64; 4]) -> FieldElement

Create a new FieldElement from its Montgomery representation

source

pub fn from_dec_str(value: &str) -> Result<FieldElement, FromStrError>

source

pub fn from_hex_be(value: &str) -> Result<FieldElement, FromStrError>

source

pub fn from_bytes_be( bytes: &[u8; 32] ) -> Result<FieldElement, FromByteArrayError>

Attempts to convert a big-endian byte representation of a field element into an element of this prime field. Returns error if the input is not canonical (is not smaller than the field’s modulus).

Arguments
  • bytes: The byte array in big endian format
source

pub fn from_byte_slice_be( bytes: &[u8] ) -> Result<FieldElement, FromByteSliceError>

Same as from_bytes_be except this function takes a slice.

source

pub fn to_bits_le(self) -> [bool; 256]

Transforms FieldElement into little endian bit representation.

source

pub fn to_bytes_be(&self) -> [u8; 32]

Convert the field element into a big-endian byte representation

source

pub const fn into_mont(self) -> [u64; 4]

Transforms FieldElement into its Montgomery representation

source

pub fn invert(&self) -> Option<FieldElement>

source

pub fn sqrt(&self) -> Option<FieldElement>

source

pub fn floor_div(&self, rhs: FieldElement) -> FieldElement

Performs a floor division. It’s not implemented as the Div trait on purpose to distinguish from the “felt division”.

Trait Implementations§

source§

impl Add<FieldElement> for FieldElement

§

type Output = FieldElement

The resulting type after applying the + operator.
source§

fn add(self, rhs: FieldElement) -> <FieldElement as Add<FieldElement>>::Output

Performs the + operation. Read more
source§

impl AddAssign<FieldElement> for FieldElement

source§

fn add_assign(&mut self, rhs: FieldElement)

Performs the += operation. Read more
source§

impl BitAnd<FieldElement> for FieldElement

§

type Output = FieldElement

The resulting type after applying the & operator.
source§

fn bitand( self, rhs: FieldElement ) -> <FieldElement as BitAnd<FieldElement>>::Output

Performs the & operation. Read more
source§

impl BitOr<FieldElement> for FieldElement

§

type Output = FieldElement

The resulting type after applying the | operator.
source§

fn bitor( self, rhs: FieldElement ) -> <FieldElement as BitOr<FieldElement>>::Output

Performs the | operation. Read more
source§

impl Clone for FieldElement

source§

fn clone(&self) -> FieldElement

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

impl Debug for FieldElement

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for FieldElement

source§

fn default() -> FieldElement

Returns the “default value” for a type. Read more
source§

impl Display for FieldElement

source§

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

Formats the value using the given formatter. Read more
source§

impl From<u16> for FieldElement

source§

fn from(value: u16) -> FieldElement

Converts to this type from the input type.
source§

impl From<u32> for FieldElement

source§

fn from(value: u32) -> FieldElement

Converts to this type from the input type.
source§

impl From<u64> for FieldElement

source§

fn from(value: u64) -> FieldElement

Converts to this type from the input type.
source§

impl From<u8> for FieldElement

source§

fn from(value: u8) -> FieldElement

Converts to this type from the input type.
source§

impl From<usize> for FieldElement

source§

fn from(value: usize) -> FieldElement

Converts to this type from the input type.
source§

impl FromStr for FieldElement

§

type Err = FromStrError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<FieldElement, <FieldElement as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for FieldElement

source§

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

impl LowerHex for FieldElement

source§

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

Formats the value using the given formatter.
source§

impl Mul<FieldElement> for FieldElement

§

type Output = FieldElement

The resulting type after applying the * operator.
source§

fn mul(self, rhs: FieldElement) -> <FieldElement as Mul<FieldElement>>::Output

Performs the * operation. Read more
source§

impl MulAssign<FieldElement> for FieldElement

source§

fn mul_assign(&mut self, rhs: FieldElement)

Performs the *= operation. Read more
source§

impl Neg for FieldElement

§

type Output = FieldElement

The resulting type after applying the - operator.
source§

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

Performs the unary - operation. Read more
source§

impl Ord for FieldElement

source§

fn cmp(&self, other: &FieldElement) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

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

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

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

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

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

Restrict a value to a certain interval. Read more
source§

impl PartialEq<FieldElement> for FieldElement

source§

fn eq(&self, other: &FieldElement) -> 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.
source§

impl PartialOrd<FieldElement> for FieldElement

source§

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

This method returns an ordering between self and other values if one exists. Read more
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
source§

impl Rem<FieldElement> for FieldElement

§

type Output = FieldElement

The resulting type after applying the % operator.
source§

fn rem(self, rhs: FieldElement) -> <FieldElement as Rem<FieldElement>>::Output

Performs the % operation. Read more
source§

impl Sub<FieldElement> for FieldElement

§

type Output = FieldElement

The resulting type after applying the - operator.
source§

fn sub(self, rhs: FieldElement) -> <FieldElement as Sub<FieldElement>>::Output

Performs the - operation. Read more
source§

impl SubAssign<FieldElement> for FieldElement

source§

fn sub_assign(&mut self, rhs: FieldElement)

Performs the -= operation. Read more
source§

impl UpperHex for FieldElement

source§

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

Formats the value using the given formatter.
source§

impl Copy for FieldElement

source§

impl Eq for FieldElement

source§

impl StructuralEq for FieldElement

source§

impl StructuralPartialEq for FieldElement

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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
source§

impl<T> ToString for Twhere 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 Twhere 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 Twhere 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.
§

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

§

fn vzip(self) -> V