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
§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
§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
§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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.