pub trait AbstractField:
Sized
+ Default
+ Clone
+ Add<Output = Self>
+ AddAssign
+ Sub<Output = Self>
+ SubAssign
+ Neg<Output = Self>
+ Mul<Output = Self>
+ MulAssign
+ Sum
+ Product
+ Debug {
type F: Field;
const ZERO: Self;
const ONE: Self;
const TWO: Self;
const NEG_ONE: Self;
Show 23 methods
// Required methods
fn from_f(f: Self::F) -> Self;
fn from_bool(b: bool) -> Self;
fn from_canonical_u8(n: u8) -> Self;
fn from_canonical_u16(n: u16) -> Self;
fn from_canonical_u32(n: u32) -> Self;
fn from_canonical_u64(n: u64) -> Self;
fn from_canonical_usize(n: usize) -> Self;
fn from_wrapped_u32(n: u32) -> Self;
fn from_wrapped_u64(n: u64) -> Self;
// Provided methods
fn double(&self) -> Self { ... }
fn square(&self) -> Self { ... }
fn cube(&self) -> Self { ... }
fn exp_u64(&self, power: u64) -> Self { ... }
fn exp_const_u64<const POWER: u64>(&self) -> Self { ... }
fn exp_power_of_2(&self, power_log: usize) -> Self { ... }
fn mul_2exp_u64(&self, exp: u64) -> Self { ... }
fn powers(&self) -> Powers<Self> ⓘ { ... }
fn shifted_powers(&self, start: Self) -> Powers<Self> ⓘ { ... }
fn powers_packed<P: PackedField<Scalar = Self>>(
&self,
) -> PackedPowers<Self, P> ⓘ { ... }
fn shifted_powers_packed<P: PackedField<Scalar = Self>>(
&self,
start: Self,
) -> PackedPowers<Self, P> ⓘ { ... }
fn dot_product<const N: usize>(u: &[Self; N], v: &[Self; N]) -> Self { ... }
fn try_div<Rhs>(self, rhs: Rhs) -> Option<<Self as Mul<Rhs>>::Output>
where Rhs: Field,
Self: Mul<Rhs> { ... }
fn zero_vec(len: usize) -> Vec<Self> { ... }
}
Expand description
A generalization of Field
which permits things like
- an actual field element
- a symbolic expression which would evaluate to a field element
- an array of field elements
Required Associated Constants§
Required Associated Types§
Required Methods§
fn from_f(f: Self::F) -> Self
Sourcefn from_canonical_u8(n: u8) -> Self
fn from_canonical_u8(n: u8) -> Self
Convert from a canonical u8
.
If the input is not canonical, i.e. if it exceeds the field’s characteristic, then the behavior is undefined.
Sourcefn from_canonical_u16(n: u16) -> Self
fn from_canonical_u16(n: u16) -> Self
Convert from a canonical u16
.
If the input is not canonical, i.e. if it exceeds the field’s characteristic, then the behavior is undefined.
Sourcefn from_canonical_u32(n: u32) -> Self
fn from_canonical_u32(n: u32) -> Self
Convert from a canonical u32
.
If the input is not canonical, i.e. if it exceeds the field’s characteristic, then the behavior is undefined.
Sourcefn from_canonical_u64(n: u64) -> Self
fn from_canonical_u64(n: u64) -> Self
Convert from a canonical u64
.
If the input is not canonical, i.e. if it exceeds the field’s characteristic, then the behavior is undefined.
Sourcefn from_canonical_usize(n: usize) -> Self
fn from_canonical_usize(n: usize) -> Self
Convert from a canonical usize
.
If the input is not canonical, i.e. if it exceeds the field’s characteristic, then the behavior is undefined.
fn from_wrapped_u32(n: u32) -> Self
fn from_wrapped_u64(n: u64) -> Self
Provided Methods§
fn double(&self) -> Self
fn square(&self) -> Self
fn cube(&self) -> Self
Sourcefn exp_u64(&self, power: u64) -> Self
fn exp_u64(&self, power: u64) -> Self
Exponentiation by a u64
power.
The default implementation calls exp_u64_generic
, which by default performs exponentiation
by squaring. Rather than override this method, it is generally recommended to have the
concrete field type override exp_u64_generic
, so that any optimizations will apply to all
abstract fields.
fn exp_const_u64<const POWER: u64>(&self) -> Self
fn exp_power_of_2(&self, power_log: usize) -> Self
Sourcefn mul_2exp_u64(&self, exp: u64) -> Self
fn mul_2exp_u64(&self, exp: u64) -> Self
self * 2^exp
fn powers(&self) -> Powers<Self> ⓘ
fn shifted_powers(&self, start: Self) -> Powers<Self> ⓘ
fn powers_packed<P: PackedField<Scalar = Self>>(&self) -> PackedPowers<Self, P> ⓘ
fn shifted_powers_packed<P: PackedField<Scalar = Self>>( &self, start: Self, ) -> PackedPowers<Self, P> ⓘ
fn dot_product<const N: usize>(u: &[Self; N], v: &[Self; N]) -> Self
fn try_div<Rhs>(self, rhs: Rhs) -> Option<<Self as Mul<Rhs>>::Output>
Sourcefn zero_vec(len: usize) -> Vec<Self>
fn zero_vec(len: usize) -> Vec<Self>
Allocates a vector of zero elements of length len
. Many operating systems zero pages
before assigning them to a userspace process. In that case, our process should not need to
write zeros, which would be redundant. However, the compiler may not always recognize this.
In particular, vec![Self::ZERO; len]
appears to result in redundant userspace zeroing.
This is the default implementation, but implementors may wish to provide their own
implementation which transmutes something like vec![0u32; len]
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.