Cartridge

Trait Cartridge 

Source
pub trait Cartridge {
    type Target: UnsignedPrimitive;
    type AssumePrimeModulus: TypedBool;
    type AssumeAlwaysAdjusted: TypedBool;
    type Equality: TypedBool;
    type Order: TypedBool;
    type Deref: TypedBool;
    type PartialAddition: TypedBool;
    type PartialSubtraction: TypedBool;
    type PartialMultiplication: TypedBool;
    type PartialDivision: TypedBool;
    type FlexibleRhs: TypedBool;

Show 47 methods // Provided methods fn new<T: PrimInt>(raw: T, modulus: T) -> T { ... } fn should_adjust<T: PrimInt>(raw: T, modulus: T) -> bool { ... } fn adjust<T: PrimInt>(raw: &mut T, modulus: T) { ... } fn adjusted<T: PrimInt>(raw: T, modulus: T) -> T { ... } fn sqrt(value: Self::Target, modulus: Self::Target) -> Option<Self::Target> where Self::PartialMultiplication: IsTrue { ... } fn from_u8(value: u8, modulus: Self::Target) -> Self::Target { ... } fn from_u16(value: u16, modulus: Self::Target) -> Self::Target { ... } fn from_u32(value: u32, modulus: Self::Target) -> Self::Target { ... } fn from_u64(value: u64, modulus: Self::Target) -> Self::Target { ... } fn from_u128(value: u128, modulus: Self::Target) -> Self::Target { ... } fn from_usize(value: usize, modulus: Self::Target) -> Self::Target { ... } fn from_i8(value: i8, modulus: Self::Target) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn from_i16(value: i16, modulus: Self::Target) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn from_i32(value: i32, modulus: Self::Target) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn from_i64(value: i64, modulus: Self::Target) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn from_i128(value: i128, modulus: Self::Target) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn from_isize(value: isize, modulus: Self::Target) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn from_float_prim<F: FloatPrimitive>( value: F, modulus: Self::Target, ) -> Self::Target where Self::AssumePrimeModulus: IsTrue, Self::PartialSubtraction: IsTrue, Self::PartialMultiplication: IsTrue, Self::PartialDivision: IsTrue { ... } fn from_biguint(value: BigUint, modulus: Self::Target) -> Self::Target { ... } fn from_bigint(value: BigInt, modulus: Self::Target) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn from_biguint_ratio( value: Ratio<BigUint>, modulus: Self::Target, ) -> Self::Target where Self::AssumePrimeModulus: IsTrue, Self::PartialDivision: IsTrue { ... } fn from_bigint_ratio( value: Ratio<BigInt>, modulus: Self::Target, ) -> Self::Target where Self::AssumePrimeModulus: IsTrue, Self::PartialSubtraction: IsTrue, Self::PartialDivision: IsTrue { ... } fn eq(lhs: Self::Target, rhs: Self::Target, modulus: Self::Target) -> bool where Self::Equality: IsTrue { ... } fn cmp( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Ordering where Self::Equality: IsTrue, Self::Order: IsTrue { ... } fn fmt_display( value: Self::Target, modulus: Self::Target, fmt: &mut Formatter<'_>, ) -> Result { ... } fn fmt_debug( value: Self::Target, modulus: Self::Target, _ty: &'static str, fmt: &mut Formatter<'_>, ) -> Result { ... } fn from_str( str: &str, modulus: Self::Target, ) -> Result<Self::Target, ParseIntError> { ... } fn neg(value: Self::Target, modulus: Self::Target) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn add( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target where Self::PartialAddition: IsTrue { ... } fn sub( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target where Self::PartialSubtraction: IsTrue { ... } fn mul( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target where Self::PartialMultiplication: IsTrue { ... } fn div( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target where Self::PartialDivision: IsTrue { ... } fn rem( _lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target where Self::PartialDivision: IsTrue { ... } fn inv(value: Self::Target, modulus: Self::Target) -> Self::Target where Self::PartialDivision: IsTrue { ... } fn from_str_radix( str: &str, radix: u32, modulus: Self::Target, ) -> Result<Self::Target, ParseIntError> where Self::AssumePrimeModulus: IsTrue, Self::Equality: IsTrue, Self::Order: IsTrue, Self::PartialAddition: IsTrue, Self::PartialSubtraction: IsTrue, Self::PartialMultiplication: IsTrue, Self::PartialDivision: IsTrue { ... } fn zero(_modulus: Self::Target) -> Self::Target where Self::PartialAddition: IsTrue { ... } fn is_zero(value: Self::Target, modulus: Self::Target) -> bool where Self::PartialAddition: IsTrue { ... } fn one(_modulus: Self::Target) -> Self::Target where Self::PartialMultiplication: IsTrue { ... } fn is_one(value: Self::Target, modulus: Self::Target) -> bool where Self::Equality: IsTrue, Self::PartialMultiplication: IsTrue { ... } fn checked_neg( value: Self::Target, modulus: Self::Target, ) -> Option<Self::Target> where Self::PartialSubtraction: IsTrue { ... } fn checked_add( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target> where Self::PartialAddition: IsTrue { ... } fn checked_sub( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target> where Self::PartialSubtraction: IsTrue { ... } fn checked_mul( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target> where Self::PartialMultiplication: IsTrue { ... } fn checked_div( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target> where Self::PartialDivision: IsTrue { ... } fn checked_rem( _lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target> where Self::PartialDivision: IsTrue { ... } fn pow_unsigned<E: UnsignedPrimitive>( base: Self::Target, exp: E, modulus: Self::Target, ) -> Self::Target where Self::PartialMultiplication: IsTrue { ... } fn pow_signed<E: SignedPrimitive>( base: Self::Target, exp: E, modulus: Self::Target, ) -> Self::Target where Self::AssumePrimeModulus: IsTrue, Self::PartialMultiplication: IsTrue, Self::PartialDivision: IsTrue { ... }
}
Expand description

Actual implementation.

Note that in the default assumes:

  • The modulus is larger than 1.
  • (modulus - 1) + (modulus - 1) does not overflow.
  • (modulus - 1) * (modulus - 1) does not overflow.

Required Associated Types§

Provided Methods§

Source

fn new<T: PrimInt>(raw: T, modulus: T) -> T

Implementation for From<Self::Target> and modtype{, ::thread_local}::ModType::new.

This method should not be overridden.

Source

fn should_adjust<T: PrimInt>(raw: T, modulus: T) -> bool

Whether to call Self::adjust.

The default implementation returns raw >= modulus. If Self::AssumeAlwaysAdjusted, this method should not be overridden.

Source

fn adjust<T: PrimInt>(raw: &mut T, modulus: T)

Make *raw *raw % modulus.

This method should not be overridden.

Source

fn adjusted<T: PrimInt>(raw: T, modulus: T) -> T

Make raw raw % modulus.

This method should not be overridden.

Source

fn sqrt(value: Self::Target, modulus: Self::Target) -> Option<Self::Target>

Implementation for modtype{, ::thread_local, ::non_static}::ModType::sqrt.

The default implementation uses Tonelli–Shanks algorithm.

§Panics

The default implementation always panics if Self::AssumePrimeModulus is False.

Source

fn from_u8(value: u8, modulus: Self::Target) -> Self::Target

Implementation for From::<u8> and FromPrimitive::from_u8.

Source

fn from_u16(value: u16, modulus: Self::Target) -> Self::Target

Implementation for From::<u16> and FromPrimitive::from_u16.

Source

fn from_u32(value: u32, modulus: Self::Target) -> Self::Target

Implementation for From::<u32> and FromPrimitive::from_u32.

Source

fn from_u64(value: u64, modulus: Self::Target) -> Self::Target

Implementation for From::<u64> and FromPrimitive::from_u64.

Source

fn from_u128(value: u128, modulus: Self::Target) -> Self::Target

Implementation for From::<u128> and FromPrimitive::from_u128.

Source

fn from_usize(value: usize, modulus: Self::Target) -> Self::Target

Implementation for From::<usize> and FromPrimitive::from_usize.

Source

fn from_i8(value: i8, modulus: Self::Target) -> Self::Target

Implementation for From::<i8> and FromPrimitive::from_i8.

Source

fn from_i16(value: i16, modulus: Self::Target) -> Self::Target

Implementation for From::<i16> and FromPrimitive::from_i16.

Source

fn from_i32(value: i32, modulus: Self::Target) -> Self::Target

Implementation for From::<i32> and FromPrimitive::from_i32.

Source

fn from_i64(value: i64, modulus: Self::Target) -> Self::Target

Implementation for From::<i64> and FromPrimitive::from_i64.

Source

fn from_i128(value: i128, modulus: Self::Target) -> Self::Target

Implementation for From::<i128> and FromPrimitive::from_i128.

Source

fn from_isize(value: isize, modulus: Self::Target) -> Self::Target

Implementation for From::<isize> and FromPrimitive::from_isize.

Source

fn from_float_prim<F: FloatPrimitive>( value: F, modulus: Self::Target, ) -> Self::Target

Implementation for From::<f32, f64> and FromPrimitive::{from_f32, from_f64}.

Source

fn from_biguint(value: BigUint, modulus: Self::Target) -> Self::Target

Implementation for From<BigUint>.

Source

fn from_bigint(value: BigInt, modulus: Self::Target) -> Self::Target

Implementation for From<BigInt>.

Source

fn from_biguint_ratio( value: Ratio<BigUint>, modulus: Self::Target, ) -> Self::Target

Implementation for From<Ratio<BigUint>>.

Source

fn from_bigint_ratio( value: Ratio<BigInt>, modulus: Self::Target, ) -> Self::Target

Implementation for From<Ratio<BigInt>>.

Source

fn eq(lhs: Self::Target, rhs: Self::Target, modulus: Self::Target) -> bool
where Self::Equality: IsTrue,

Implementation for PartialEq::eq.

Source

fn cmp(lhs: Self::Target, rhs: Self::Target, modulus: Self::Target) -> Ordering
where Self::Equality: IsTrue, Self::Order: IsTrue,

Implementation for PartialOrd::partial_cmp and Ord::cmp.

Source

fn fmt_display( value: Self::Target, modulus: Self::Target, fmt: &mut Formatter<'_>, ) -> Result

Implementation for Display.

Source

fn fmt_debug( value: Self::Target, modulus: Self::Target, _ty: &'static str, fmt: &mut Formatter<'_>, ) -> Result

Implementation for Debug.

Source

fn from_str( str: &str, modulus: Self::Target, ) -> Result<Self::Target, ParseIntError>

Implementation for FromStr.

Source

fn neg(value: Self::Target, modulus: Self::Target) -> Self::Target

Implementation for Neg.

Source

fn add( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target
where Self::PartialAddition: IsTrue,

Implementation for Add.

Source

fn sub( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target

Implementation for Sub.

Source

fn mul( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target

Implementation for Mul.

Source

fn div( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target
where Self::PartialDivision: IsTrue,

Implementation for Div.

The default implementation is based on this article.

§Panics

The default implementation panics if:

  • rhs⁻¹ does not exist.
Source

fn rem( _lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Self::Target
where Self::PartialDivision: IsTrue,

Implementation for Rem.

The default implementation always returns 0.

§Panics

The default implementation panics if:

  • rhs is 0.
  • gcd(rhs, modulus) is not 1.
Source

fn inv(value: Self::Target, modulus: Self::Target) -> Self::Target
where Self::PartialDivision: IsTrue,

Implementation for Inv.

§Panics

The default implementation panics if value⁻¹ does not exist.

Source

fn from_str_radix( str: &str, radix: u32, modulus: Self::Target, ) -> Result<Self::Target, ParseIntError>

Implementation for Num.

Source

fn zero(_modulus: Self::Target) -> Self::Target
where Self::PartialAddition: IsTrue,

Implementation for Zero::zero.

Source

fn is_zero(value: Self::Target, modulus: Self::Target) -> bool
where Self::PartialAddition: IsTrue,

Implementation for Zero::is_zero.

Source

fn one(_modulus: Self::Target) -> Self::Target

Implementation for One::one.

Source

fn is_one(value: Self::Target, modulus: Self::Target) -> bool

Implementation for One::is_one.

Source

fn checked_neg( value: Self::Target, modulus: Self::Target, ) -> Option<Self::Target>

Implementation for CheckedNeg.

Source

fn checked_add( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target>
where Self::PartialAddition: IsTrue,

Implementation for CheckedAdd.

Source

fn checked_sub( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target>

Implementation for CheckedSub.

Source

fn checked_mul( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target>

Implementation for CheckedMul.

Source

fn checked_div( lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target>
where Self::PartialDivision: IsTrue,

Implementation for CheckedDiv.

Source

fn checked_rem( _lhs: Self::Target, rhs: Self::Target, modulus: Self::Target, ) -> Option<Self::Target>
where Self::PartialDivision: IsTrue,

Implementation for CheckedRem.

Source

fn pow_unsigned<E: UnsignedPrimitive>( base: Self::Target, exp: E, modulus: Self::Target, ) -> Self::Target

Implementation for Pow<{u8, u16, u32, u64, u128, usize}>.

Source

fn pow_signed<E: SignedPrimitive>( base: Self::Target, exp: E, modulus: Self::Target, ) -> Self::Target

Implementation for Pow<{i8, i16, i32, i64, i128, isize}>.

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.

Implementors§

Source§

impl<C: Cartridge> Cartridge for AllowFlexibleRhs<C>

Source§

impl<T: UnsignedPrimitive> Cartridge for Additive<T>

Source§

impl<T: UnsignedPrimitive> Cartridge for Field<T>

Source§

impl<T: UnsignedPrimitive> Cartridge for ManuallyAdjust<T>

Source§

impl<T: UnsignedPrimitive> Cartridge for Multiplicative<T>