pub struct Felt(/* 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 AddAssign<&Felt> for Felt
Field addition. Never overflows/underflows.
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
Field addition. Never overflows/underflows.
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
Defaults to Felt::ZERO.
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 FeltWriter for Felt
impl FeltWriter for Felt
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<EthAddress> for Felt
impl From<EthAddress> for Felt
Source§fn from(value: EthAddress) -> Felt
fn from(value: EthAddress) -> Felt
Source§impl From<EthAddress> for Felt
impl From<EthAddress> for Felt
Source§fn from(value: EthAddress) -> Felt
fn from(value: EthAddress) -> Felt
Source§impl From<LegacyEntrypointOffset> for Felt
impl From<LegacyEntrypointOffset> for Felt
Source§fn from(value: LegacyEntrypointOffset) -> Felt
fn from(value: LegacyEntrypointOffset) -> Felt
Source§impl From<LegacyEntrypointOffset> for Felt
impl From<LegacyEntrypointOffset> for Felt
Source§fn from(value: LegacyEntrypointOffset) -> Felt
fn from(value: LegacyEntrypointOffset) -> Felt
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 MulAssign<&Felt> for Felt
Field multiplication. Never overflows/underflows.
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
Field multiplication. Never overflows/underflows.
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 SizeOf for Felt
impl SizeOf for Felt
Source§fn size_of_children(&self, _context: &mut Context)
fn size_of_children(&self, _context: &mut Context)
Source§fn size_of_with_context(&self, context: &mut Context)
fn size_of_with_context(&self, context: &mut Context)
Context,
including both the size of the value itself and all of its childrenSource§impl SubAssign<&Felt> for Felt
Field subtraction. Never overflows/underflows.
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
Field subtraction. Never overflows/underflows.
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.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§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.