pub struct FieldElement { /* private fields */ }Implementations§
Source§impl FieldElement
impl FieldElement
Sourcepub const ZERO: FieldElement
pub const ZERO: FieldElement
FieldElement constant that’s equal to 0
Sourcepub const ONE: FieldElement
pub const ONE: FieldElement
FieldElement constant that’s equal to 1
Sourcepub const TWO: FieldElement
pub const TWO: FieldElement
FieldElement constant that’s equal to 2
Sourcepub const THREE: FieldElement
pub const THREE: FieldElement
FieldElement constant that’s equal to 3
Sourcepub const MAX: FieldElement
pub const MAX: FieldElement
Maximum value of FieldElement. Equals to 2^251 + 17 * 2^192.
Sourcepub const fn from_mont(data: [u64; 4]) -> Self
pub const fn from_mont(data: [u64; 4]) -> Self
Create a new FieldElement from its Montgomery representation
pub fn from_dec_str(value: &str) -> Result<Self, FromStrError>
pub fn from_hex_be(value: &str) -> Result<Self, FromStrError>
Sourcepub fn from_bytes_be(bytes: &[u8; 32]) -> Result<Self, FromByteArrayError>
pub fn from_bytes_be(bytes: &[u8; 32]) -> Result<Self, 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
Sourcepub fn from_byte_slice_be(bytes: &[u8]) -> Result<Self, FromByteSliceError>
pub fn from_byte_slice_be(bytes: &[u8]) -> Result<Self, FromByteSliceError>
Same as from_bytes_be except this function takes a slice.
Sourcepub fn to_big_decimal<D: Into<i64>>(&self, decimals: D) -> BigDecimal
pub fn to_big_decimal<D: Into<i64>>(&self, decimals: D) -> BigDecimal
Interprets the field element as a decimal number of a certain decimal places.
Sourcepub fn to_bits_le(self) -> [bool; 256]
pub fn to_bits_le(self) -> [bool; 256]
Transforms FieldElement into little endian bit representation.
Sourcepub fn to_bytes_be(&self) -> [u8; 32]
pub fn to_bytes_be(&self) -> [u8; 32]
Convert the field element into a big-endian byte representation
Sourcepub const fn into_mont(self) -> [u64; 4]
pub const fn into_mont(self) -> [u64; 4]
Transforms FieldElement into its Montgomery representation
pub fn invert(&self) -> Option<FieldElement>
pub fn sqrt(&self) -> Option<FieldElement>
pub fn double(&self) -> FieldElement
Sourcepub fn floor_div(&self, rhs: FieldElement) -> FieldElement
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 for FieldElement
impl Add for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
+ operator.Source§impl AddAssign for FieldElement
impl AddAssign for FieldElement
Source§fn add_assign(&mut self, rhs: FieldElement)
fn add_assign(&mut self, rhs: FieldElement)
+= operation. Read moreSource§impl AsRef<FieldElement> for FieldElement
impl AsRef<FieldElement> for FieldElement
Source§fn as_ref(&self) -> &FieldElement
fn as_ref(&self) -> &FieldElement
Source§impl BitAnd for FieldElement
impl BitAnd for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
& operator.Source§impl BitOr for FieldElement
impl BitOr for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
| operator.Source§impl Clone for FieldElement
impl Clone for FieldElement
Source§fn clone(&self) -> FieldElement
fn clone(&self) -> FieldElement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FieldElement
impl Debug for FieldElement
Source§impl Default for FieldElement
impl Default for FieldElement
Source§impl<'de> Deserialize<'de> for FieldElement
impl<'de> Deserialize<'de> for FieldElement
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for FieldElement
impl Display for FieldElement
Source§impl From<&FieldElement> for U256
impl From<&FieldElement> for U256
Source§fn from(value: &FieldElement) -> Self
fn from(value: &FieldElement) -> Self
Source§impl From<u128> for FieldElement
impl From<u128> for FieldElement
Source§impl From<u16> for FieldElement
impl From<u16> for FieldElement
Source§impl From<u32> for FieldElement
impl From<u32> for FieldElement
Source§impl From<u64> for FieldElement
impl From<u64> for FieldElement
Source§impl From<u8> for FieldElement
impl From<u8> for FieldElement
Source§impl From<usize> for FieldElement
impl From<usize> for FieldElement
Source§impl FromStr for FieldElement
impl FromStr for FieldElement
Source§impl Hash for FieldElement
impl Hash for FieldElement
Source§impl LowerHex for FieldElement
impl LowerHex for FieldElement
Source§impl Mul for FieldElement
impl Mul for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
* operator.Source§impl MulAssign for FieldElement
impl MulAssign for FieldElement
Source§fn mul_assign(&mut self, rhs: FieldElement)
fn mul_assign(&mut self, rhs: FieldElement)
*= operation. Read moreSource§impl Neg for FieldElement
impl Neg for FieldElement
Source§impl Ord for FieldElement
impl Ord for FieldElement
Source§fn cmp(&self, other: &FieldElement) -> Ordering
fn cmp(&self, other: &FieldElement) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for FieldElement
impl PartialEq for FieldElement
Source§impl PartialOrd for FieldElement
impl PartialOrd for FieldElement
Source§impl Rem for FieldElement
impl Rem for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
% operator.Source§impl Serialize for FieldElement
impl Serialize for FieldElement
Source§impl Sub for FieldElement
impl Sub for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
- operator.Source§impl SubAssign for FieldElement
impl SubAssign for FieldElement
Source§fn sub_assign(&mut self, rhs: FieldElement)
fn sub_assign(&mut self, rhs: FieldElement)
-= operation. Read moreSource§impl<'a> Sum<&'a FieldElement> for FieldElement
impl<'a> Sum<&'a FieldElement> for FieldElement
Source§fn sum<I: Iterator<Item = &'a FieldElement>>(iter: I) -> Self
fn sum<I: Iterator<Item = &'a FieldElement>>(iter: I) -> Self
Self from the elements by “summing up”
the items.