pub struct Felt252(/* private fields */);
Expand description
Definition of the Field Element type.
Implementations§
Source§impl Felt
impl Felt
Sourcepub const ELEMENT_UPPER_BOUND: Felt = _
pub const ELEMENT_UPPER_BOUND: Felt = _
2 ** 251
Sourcepub const fn from_raw(val: [u64; 4]) -> Felt
pub const fn from_raw(val: [u64; 4]) -> Felt
Creates a new Felt from the raw internal representation. See UnsignedInteger to understand how it works under the hood.
pub const fn from_hex_unchecked(val: &str) -> Felt
Sourcepub fn from_bytes_be(bytes: &[u8; 32]) -> Felt
pub fn from_bytes_be(bytes: &[u8; 32]) -> Felt
Creates a new Felt from its big-endian representation in a [u8; 32] array. This is as performant as from_bytes_le.
Sourcepub fn from_bytes_le(bytes: &[u8; 32]) -> Felt
pub fn from_bytes_le(bytes: &[u8; 32]) -> Felt
Creates a new Felt from its little-endian representation in a [u8; 32] array. This is as performant as from_bytes_le.
Sourcepub fn from_bytes_be_slice(bytes: &[u8]) -> Felt
pub fn from_bytes_be_slice(bytes: &[u8]) -> Felt
Creates a new Felt from its big-endian representation in a u8 slice. This is as performant as from_bytes_le. All bytes in the slice are consumed, as if first creating a big integer from them, but the conversion is performed in constant space on the stack.
Sourcepub fn from_bytes_le_slice(bytes: &[u8]) -> Felt
pub fn from_bytes_le_slice(bytes: &[u8]) -> Felt
Creates a new Felt from its little-endian representation in a u8 slice. This is as performant as from_bytes_be. All bytes in the slice are consumed, as if first creating a big integer from them, but the conversion is performed in constant space on the stack.
Sourcepub fn to_bytes_be(&self) -> [u8; 32]
pub fn to_bytes_be(&self) -> [u8; 32]
Converts to big-endian byte representation in a u8 array. This is as performant as to_bytes_le
Sourcepub fn to_bytes_le(&self) -> [u8; 32]
pub fn to_bytes_le(&self) -> [u8; 32]
Converts to little-endian byte representation in a u8 array. This is as performant as to_bytes_be
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Helper to produce a hexadecimal formatted string.
Equivalent to calling format!("{self:#x}")
.
Sourcepub fn to_fixed_hex_string(&self) -> String
pub fn to_fixed_hex_string(&self) -> String
Helper to produce a hexadecimal formatted string of 66 chars.
Sourcepub fn to_bits_le(&self) -> [bool; 256]
pub fn to_bits_le(&self) -> [bool; 256]
Converts to little-endian bit representation.
Sourcepub fn to_bits_be(&self) -> [bool; 256]
pub fn to_bits_be(&self) -> [bool; 256]
Converts to big-endian bit representation.
Sourcepub fn field_div(&self, rhs: &NonZeroFelt) -> Felt
pub fn field_div(&self, rhs: &NonZeroFelt) -> Felt
Finite field division.
Sourcepub fn floor_div(&self, rhs: &NonZeroFelt) -> Felt
pub fn floor_div(&self, rhs: &NonZeroFelt) -> Felt
Truncated quotient between self
and rhs
.
Sourcepub fn div_rem(&self, rhs: &NonZeroFelt) -> (Felt, Felt)
pub fn div_rem(&self, rhs: &NonZeroFelt) -> (Felt, Felt)
Quotient and remainder between self
and rhs
.
Sourcepub fn sqrt(&self) -> Option<Felt>
pub fn sqrt(&self) -> Option<Felt>
Finds the square root. There may be 2 roots for each square, and the lower one is returned.
Sourcepub fn mul_mod(&self, rhs: &Felt, p: &NonZeroFelt) -> Felt
pub fn mul_mod(&self, rhs: &Felt, p: &NonZeroFelt) -> Felt
Modular multiplication between self
and rhs
in modulo p
.
Sourcepub fn mod_inverse(&self, p: &NonZeroFelt) -> Option<Felt>
pub fn mod_inverse(&self, p: &NonZeroFelt) -> Option<Felt>
Multiplicative inverse of self
in modulo p
.
Sourcepub fn mod_floor(&self, n: &NonZeroFelt) -> Felt
pub fn mod_floor(&self, n: &NonZeroFelt) -> Felt
Remainder of dividing self
by n
as integers.
Sourcepub fn from_hex(hex_string: &str) -> Result<Felt, FromStrError>
pub fn from_hex(hex_string: &str) -> Result<Felt, FromStrError>
Parse a hex-encoded number into Felt
.
Sourcepub fn from_dec_str(dec_string: &str) -> Result<Felt, FromStrError>
pub fn from_dec_str(dec_string: &str) -> Result<Felt, FromStrError>
Parse a decimal-encoded number into Felt
.
Sourcepub fn to_raw_reversed(&self) -> [u64; 4]
pub fn to_raw_reversed(&self) -> [u64; 4]
Returns the internal representation of a felt and reverses it to match starknet-rs mont representation
Sourcepub fn to_le_digits(&self) -> [u64; 4]
pub fn to_le_digits(&self) -> [u64; 4]
Convert self
’s representative into an array of u64
digits,
least significant digits first.
Sourcepub fn to_be_digits(&self) -> [u64; 4]
pub fn to_be_digits(&self) -> [u64; 4]
Convert self
’s representative into an array of u64
digits,
most significant digits first.
Sourcepub fn bits(&self) -> usize
pub fn bits(&self) -> usize
Count the minimum number of bits needed to express self
’s representative.
pub fn to_biguint(&self) -> BigUint
pub fn to_bigint(&self) -> BigInt
Trait Implementations§
Source§impl Add<&Felt> for Relocatable
impl Add<&Felt> for Relocatable
Source§impl AddAssign<&Felt> for Felt
impl AddAssign<&Felt> for Felt
Field addition. Never overflows/underflows.
Source§fn add_assign(&mut self, rhs: &Felt)
fn add_assign(&mut self, rhs: &Felt)
+=
operation. Read moreSource§impl AddAssign for Felt
impl AddAssign for Felt
Field addition. Never overflows/underflows.
Source§fn add_assign(&mut self, rhs: Felt)
fn add_assign(&mut self, rhs: Felt)
+=
operation. Read moreSource§impl Default for Felt
impl Default for Felt
Defaults to Felt::ZERO.
Source§impl<'de> Deserialize<'de> for Felt
impl<'de> Deserialize<'de> for Felt
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Felt, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Felt, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<&Felt> for MaybeRelocatable
impl From<&Felt> for MaybeRelocatable
Source§impl From<&NonZeroFelt> for Felt
impl From<&NonZeroFelt> for Felt
Source§fn from(value: &NonZeroFelt) -> Felt
fn from(value: &NonZeroFelt) -> Felt
Source§impl From<Felt> for MaybeRelocatable
impl From<Felt> for MaybeRelocatable
Source§impl From<NonZeroFelt> for Felt
impl From<NonZeroFelt> for Felt
Source§fn from(value: NonZeroFelt) -> Felt
fn from(value: NonZeroFelt) -> Felt
Source§impl FromPrimitive for Felt
impl FromPrimitive for Felt
Source§fn from_i64(value: i64) -> Option<Felt>
fn from_i64(value: i64) -> Option<Felt>
i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u64(value: u64) -> Option<Felt>
fn from_u64(value: u64) -> Option<Felt>
u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i128(value: i128) -> Option<Felt>
fn from_i128(value: i128) -> Option<Felt>
i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moreSource§fn from_u128(value: u128) -> Option<Felt>
fn from_u128(value: u128) -> Option<Felt>
u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moreSource§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
u16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u32(n: u32) -> Option<Self>
fn from_u32(n: u32) -> Option<Self>
u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§impl Mul<Felt> for &ProjectivePoint
impl Mul<Felt> for &ProjectivePoint
Source§type Output = ProjectivePoint
type Output = ProjectivePoint
*
operator.Source§impl MulAssign<&Felt> for Felt
impl MulAssign<&Felt> for Felt
Field multiplication. Never overflows/underflows.
Source§fn mul_assign(&mut self, rhs: &Felt)
fn mul_assign(&mut self, rhs: &Felt)
*=
operation. Read moreSource§impl MulAssign for Felt
impl MulAssign for Felt
Field multiplication. Never overflows/underflows.
Source§fn mul_assign(&mut self, rhs: Felt)
fn mul_assign(&mut self, rhs: Felt)
*=
operation. Read moreSource§impl Ord for Felt
impl Ord for Felt
Source§impl PartialOrd for Felt
impl PartialOrd for Felt
Source§impl Serialize for Felt
impl Serialize for Felt
Source§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,
Source§impl SubAssign<&Felt> for Felt
impl SubAssign<&Felt> for Felt
Field subtraction. Never overflows/underflows.
Source§fn sub_assign(&mut self, rhs: &Felt)
fn sub_assign(&mut self, rhs: &Felt)
-=
operation. Read moreSource§impl SubAssign for Felt
impl SubAssign for Felt
Field subtraction. Never overflows/underflows.
Source§fn sub_assign(&mut self, rhs: Felt)
fn sub_assign(&mut self, rhs: Felt)
-=
operation. Read moreSource§impl ToBigUint for Felt
impl ToBigUint for Felt
Source§fn to_biguint(&self) -> Option<BigUint>
fn to_biguint(&self) -> Option<BigUint>
Converts the value of self
to a [BigUint
].
Safe to unwrap, will always return Some
.
Source§impl ToPrimitive for Felt
impl ToPrimitive for Felt
Source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self
to a u64
. If the value cannot be
represented by a u64
, then None
is returned.Source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self
to an i64
. If the value cannot be
represented by an i64
, then None
is returned.Source§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self
to a u128
. If the value cannot be
represented by a u128
(u64
under the default implementation), then
None
is returned. Read moreSource§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self
to an i128
. If the value cannot be
represented by an i128
(i64
under the default implementation), then
None
is returned. Read moreSource§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self
to an isize
. If the value cannot be
represented by an isize
, then None
is returned.Source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self
to an i8
. If the value cannot be
represented by an i8
, then None
is returned.Source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self
to an i16
. If the value cannot be
represented by an i16
, then None
is returned.Source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self
to an i32
. If the value cannot be
represented by an i32
, then None
is returned.Source§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self
to a usize
. If the value cannot be
represented by a usize
, then None
is returned.Source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self
to a u8
. If the value cannot be
represented by a u8
, then None
is returned.Source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self
to a u16
. If the value cannot be
represented by a u16
, then None
is returned.Source§fn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
self
to a u32
. If the value cannot be
represented by a u32
, then None
is returned.Source§impl TryFrom<&Felt> for NonZeroFelt
impl TryFrom<&Felt> for NonZeroFelt
Source§type Error = FeltIsZeroError
type Error = FeltIsZeroError
Source§fn try_from(
value: &Felt,
) -> Result<NonZeroFelt, <NonZeroFelt as TryFrom<&Felt>>::Error>
fn try_from( value: &Felt, ) -> Result<NonZeroFelt, <NonZeroFelt as TryFrom<&Felt>>::Error>
Source§impl TryFrom<Felt> for NonZeroFelt
impl TryFrom<Felt> for NonZeroFelt
Source§type Error = FeltIsZeroError
type Error = FeltIsZeroError
Source§fn try_from(
value: Felt,
) -> Result<NonZeroFelt, <NonZeroFelt as TryFrom<Felt>>::Error>
fn try_from( value: Felt, ) -> Result<NonZeroFelt, <NonZeroFelt as TryFrom<Felt>>::Error>
impl Copy for Felt
impl Eq for Felt
impl StructuralPartialEq for Felt
Auto Trait Implementations§
impl Freeze for Felt
impl RefUnwindSafe for Felt
impl Send for Felt
impl Sync for Felt
impl Unpin for Felt
impl UnwindSafe for Felt
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.