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§
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
Provided Methods§
Sourcefn new<T: PrimInt>(raw: T, modulus: T) -> T
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.
Sourcefn should_adjust<T: PrimInt>(raw: T, modulus: T) -> bool
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.
Sourcefn adjust<T: PrimInt>(raw: &mut T, modulus: T)
fn adjust<T: PrimInt>(raw: &mut T, modulus: T)
Make *raw *raw % modulus.
This method should not be overridden.
Sourcefn adjusted<T: PrimInt>(raw: T, modulus: T) -> T
fn adjusted<T: PrimInt>(raw: T, modulus: T) -> T
Make raw raw % modulus.
This method should not be overridden.
Sourcefn sqrt(value: Self::Target, modulus: Self::Target) -> Option<Self::Target>where
Self::PartialMultiplication: IsTrue,
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.
Sourcefn from_u8(value: u8, modulus: Self::Target) -> Self::Target
fn from_u8(value: u8, modulus: Self::Target) -> Self::Target
Implementation for From::<u8> and FromPrimitive::from_u8.
Sourcefn from_u16(value: u16, modulus: Self::Target) -> Self::Target
fn from_u16(value: u16, modulus: Self::Target) -> Self::Target
Implementation for From::<u16> and FromPrimitive::from_u16.
Sourcefn from_u32(value: u32, modulus: Self::Target) -> Self::Target
fn from_u32(value: u32, modulus: Self::Target) -> Self::Target
Implementation for From::<u32> and FromPrimitive::from_u32.
Sourcefn from_u64(value: u64, modulus: Self::Target) -> Self::Target
fn from_u64(value: u64, modulus: Self::Target) -> Self::Target
Implementation for From::<u64> and FromPrimitive::from_u64.
Sourcefn from_u128(value: u128, modulus: Self::Target) -> Self::Target
fn from_u128(value: u128, modulus: Self::Target) -> Self::Target
Implementation for From::<u128> and FromPrimitive::from_u128.
Sourcefn from_usize(value: usize, modulus: Self::Target) -> Self::Target
fn from_usize(value: usize, modulus: Self::Target) -> Self::Target
Implementation for From::<usize> and FromPrimitive::from_usize.
Sourcefn from_i8(value: i8, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn from_i8(value: i8, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Implementation for From::<i8> and FromPrimitive::from_i8.
Sourcefn from_i16(value: i16, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn from_i16(value: i16, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Implementation for From::<i16> and FromPrimitive::from_i16.
Sourcefn from_i32(value: i32, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn from_i32(value: i32, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Implementation for From::<i32> and FromPrimitive::from_i32.
Sourcefn from_i64(value: i64, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn from_i64(value: i64, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Implementation for From::<i64> and FromPrimitive::from_i64.
Sourcefn from_i128(value: i128, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn from_i128(value: i128, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Implementation for From::<i128> and FromPrimitive::from_i128.
Sourcefn from_isize(value: isize, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn from_isize(value: isize, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Implementation for From::<isize> and FromPrimitive::from_isize.
Sourcefn from_float_prim<F: FloatPrimitive>(
value: F,
modulus: Self::Target,
) -> Self::Targetwhere
Self::AssumePrimeModulus: IsTrue,
Self::PartialSubtraction: IsTrue,
Self::PartialMultiplication: IsTrue,
Self::PartialDivision: IsTrue,
fn from_float_prim<F: FloatPrimitive>(
value: F,
modulus: Self::Target,
) -> Self::Targetwhere
Self::AssumePrimeModulus: IsTrue,
Self::PartialSubtraction: IsTrue,
Self::PartialMultiplication: IsTrue,
Self::PartialDivision: IsTrue,
Sourcefn from_biguint(value: BigUint, modulus: Self::Target) -> Self::Target
fn from_biguint(value: BigUint, modulus: Self::Target) -> Self::Target
Sourcefn from_bigint(value: BigInt, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn from_bigint(value: BigInt, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Sourcefn from_bigint_ratio(
value: Ratio<BigInt>,
modulus: Self::Target,
) -> Self::Targetwhere
Self::AssumePrimeModulus: IsTrue,
Self::PartialSubtraction: IsTrue,
Self::PartialDivision: IsTrue,
fn from_bigint_ratio(
value: Ratio<BigInt>,
modulus: Self::Target,
) -> Self::Targetwhere
Self::AssumePrimeModulus: IsTrue,
Self::PartialSubtraction: IsTrue,
Self::PartialDivision: IsTrue,
Sourcefn cmp(lhs: Self::Target, rhs: Self::Target, modulus: Self::Target) -> Ordering
fn cmp(lhs: Self::Target, rhs: Self::Target, modulus: Self::Target) -> Ordering
Implementation for PartialOrd::partial_cmp and Ord::cmp.
Sourcefn fmt_display(
value: Self::Target,
modulus: Self::Target,
fmt: &mut Formatter<'_>,
) -> Result
fn fmt_display( value: Self::Target, modulus: Self::Target, fmt: &mut Formatter<'_>, ) -> Result
Implementation for Display.
Sourcefn fmt_debug(
value: Self::Target,
modulus: Self::Target,
_ty: &'static str,
fmt: &mut Formatter<'_>,
) -> Result
fn fmt_debug( value: Self::Target, modulus: Self::Target, _ty: &'static str, fmt: &mut Formatter<'_>, ) -> Result
Implementation for Debug.
Sourcefn from_str(
str: &str,
modulus: Self::Target,
) -> Result<Self::Target, ParseIntError>
fn from_str( str: &str, modulus: Self::Target, ) -> Result<Self::Target, ParseIntError>
Implementation for FromStr.
Sourcefn neg(value: Self::Target, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn neg(value: Self::Target, modulus: Self::Target) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Implementation for Neg.
Sourcefn add(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialAddition: IsTrue,
fn add(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialAddition: IsTrue,
Implementation for Add.
Sourcefn sub(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
fn sub(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialSubtraction: IsTrue,
Implementation for Sub.
Sourcefn mul(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialMultiplication: IsTrue,
fn mul(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialMultiplication: IsTrue,
Implementation for Mul.
Sourcefn div(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialDivision: IsTrue,
fn div(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialDivision: IsTrue,
Implementation for Div.
The default implementation is based on this article.
§Panics
The default implementation panics if:
rhs⁻¹ does not exist.
Sourcefn rem(
_lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialDivision: IsTrue,
fn rem(
_lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialDivision: IsTrue,
Sourcefn inv(value: Self::Target, modulus: Self::Target) -> Self::Targetwhere
Self::PartialDivision: IsTrue,
fn inv(value: Self::Target, modulus: Self::Target) -> Self::Targetwhere
Self::PartialDivision: IsTrue,
Sourcefn 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 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.
Sourcefn is_zero(value: Self::Target, modulus: Self::Target) -> boolwhere
Self::PartialAddition: IsTrue,
fn is_zero(value: Self::Target, modulus: Self::Target) -> boolwhere
Self::PartialAddition: IsTrue,
Sourcefn checked_neg(
value: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialSubtraction: IsTrue,
fn checked_neg(
value: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialSubtraction: IsTrue,
Implementation for CheckedNeg.
Sourcefn checked_add(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialAddition: IsTrue,
fn checked_add(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialAddition: IsTrue,
Implementation for CheckedAdd.
Sourcefn checked_sub(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialSubtraction: IsTrue,
fn checked_sub(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialSubtraction: IsTrue,
Implementation for CheckedSub.
Sourcefn checked_mul(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialMultiplication: IsTrue,
fn checked_mul(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialMultiplication: IsTrue,
Implementation for CheckedMul.
Sourcefn checked_div(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialDivision: IsTrue,
fn checked_div(
lhs: Self::Target,
rhs: Self::Target,
modulus: Self::Target,
) -> Option<Self::Target>where
Self::PartialDivision: IsTrue,
Implementation for CheckedDiv.
Sourcefn checked_rem(
_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,
Implementation for CheckedRem.
Sourcefn pow_unsigned<E: UnsignedPrimitive>(
base: Self::Target,
exp: E,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialMultiplication: IsTrue,
fn pow_unsigned<E: UnsignedPrimitive>(
base: Self::Target,
exp: E,
modulus: Self::Target,
) -> Self::Targetwhere
Self::PartialMultiplication: IsTrue,
Sourcefn pow_signed<E: SignedPrimitive>(
base: Self::Target,
exp: E,
modulus: Self::Target,
) -> Self::Targetwhere
Self::AssumePrimeModulus: IsTrue,
Self::PartialMultiplication: IsTrue,
Self::PartialDivision: IsTrue,
fn pow_signed<E: SignedPrimitive>(
base: Self::Target,
exp: E,
modulus: Self::Target,
) -> Self::Targetwhere
Self::AssumePrimeModulus: IsTrue,
Self::PartialMultiplication: IsTrue,
Self::PartialDivision: IsTrue,
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.