[][src]Trait modtype::Cartridge

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;
    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
, { ... } }

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.

Associated Types

Loading content...

Provided methods

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.

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.

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

Make *raw *raw % modulus.

This method should not be overridden.

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

Make raw raw % modulus.

This method should not be overridden.

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Implementation for From<BigUint>.

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

Implementation for From<BigInt>.

fn from_biguint_ratio(
    value: Ratio<BigUint>,
    modulus: Self::Target
) -> Self::Target where
    Self::AssumePrimeModulus: IsTrue,
    Self::PartialDivision: IsTrue

Implementation for From<Ratio<BigUint>>.

fn from_bigint_ratio(
    value: Ratio<BigInt>,
    modulus: Self::Target
) -> Self::Target where
    Self::AssumePrimeModulus: IsTrue,
    Self::PartialSubtraction: IsTrue,
    Self::PartialDivision: IsTrue

Implementation for From<Ratio<BigInt>>.

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

Implementation for PartialEq::eq.

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.

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

Implementation for Display.

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

Implementation for Debug.

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

Implementation for FromStr.

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

Implementation for Neg.

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

Implementation for Add.

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

Implementation for Sub.

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

Implementation for Mul.

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.

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.

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.

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

Implementation for Num.

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

Implementation for Zero::zero.

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

Implementation for Zero::is_zero.

fn one(_modulus: Self::Target) -> Self::Target where
    Self::PartialMultiplication: IsTrue

Implementation for One::one.

fn is_one(value: Self::Target, modulus: Self::Target) -> bool where
    Self::Equality: IsTrue,
    Self::PartialMultiplication: IsTrue

Implementation for One::is_one.

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

Implementation for CheckedNeg.

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

Implementation for CheckedAdd.

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

Implementation for CheckedSub.

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

Implementation for CheckedMul.

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

Implementation for CheckedDiv.

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

Implementation for CheckedRem.

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

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

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

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

Loading content...

Implementors

impl<C: Cartridge> Cartridge for AllowFlexibleRhs<C>[src]

type Target = C::Target

type AssumePrimeModulus = C::AssumePrimeModulus

type AssumeAlwaysAdjusted = C::AssumeAlwaysAdjusted

type Equality = C::Equality

type Order = C::Order

type Deref = C::Deref

type PartialAddition = C::PartialAddition

type PartialSubtraction = C::PartialSubtraction

type PartialMultiplication = C::PartialMultiplication

type PartialDivision = C::PartialDivision

type FlexibleRhs = True

impl<T: UnsignedPrimitive> Cartridge for Additive<T>[src]

type Target = T

type AssumePrimeModulus = False

type AssumeAlwaysAdjusted = False

type Equality = False

type Order = False

type Deref = False

type PartialAddition = True

type PartialSubtraction = False

type PartialMultiplication = False

type PartialDivision = False

type FlexibleRhs = False

impl<T: UnsignedPrimitive> Cartridge for Field<T>[src]

impl<T: UnsignedPrimitive> Cartridge for ManuallyAdjust<T>[src]

type Target = T

type AssumePrimeModulus = False

type AssumeAlwaysAdjusted = False

type Equality = False

type Order = False

type Deref = False

type PartialAddition = True

type PartialSubtraction = True

type PartialMultiplication = True

type PartialDivision = False

type FlexibleRhs = False

impl<T: UnsignedPrimitive> Cartridge for Multiplicative<T>[src]

Loading content...