pub trait QuotientMap<Int>: Sized {
// Required methods
fn from_int(int: Int) -> Self;
fn from_canonical_checked(int: Int) -> Option<Self>;
unsafe fn from_canonical_unchecked(int: Int) -> Self;
}Expand description
Implementation of the quotient map ℤ -> ℤ/p which sends an integer r to its conjugacy class [r].
This is the key trait allowing us to convert integers into field elements. Each prime field should implement this for all primitive integer types.
Required Methods§
Sourcefn from_int(int: Int) -> Self
fn from_int(int: Int) -> Self
Convert a given integer into an element of the field ℤ/p.
This is the most generic method which makes no assumptions on the size of the input.
Where possible, this method should be used with the smallest possible integer type.
For example, if a 32-bit integer x is known to be less than 2^16, then
from_int(x as u16) will often be faster than from_int(x).
This method is also strongly preferred over from_canonical_checked/from_canonical_unchecked.
It will usually be identical when Int is a small type, e.g. u8/u16 and is safer for
larger types.
Sourcefn from_canonical_checked(int: Int) -> Option<Self>
fn from_canonical_checked(int: Int) -> Option<Self>
Convert a given integer into an element of the field ℤ/p. The input is checked to
ensure it lies within a given range.
- If
Intis an unsigned integer type the input must lie in[0, p - 1]. - If
Intis a signed integer type the input must lie in[-(p - 1)/2, (p - 1)/2].
Return None if the input lies outside this range and Some(val) otherwise.
Sourceunsafe fn from_canonical_unchecked(int: Int) -> Self
unsafe fn from_canonical_unchecked(int: Int) -> Self
Convert a given integer into an element of the field ℤ/p. The input is guaranteed
to lie within a specific range depending on p. If the input lies outside of this
range, the output is undefined.
In general from_canonical_unchecked will be faster for either signed or unsigned
types but the specifics will depend on the field.
§Safety
- If
Intis an unsigned integer type then the allowed range will include[0, p - 1]. - If
Intis a signed integer type then the allowed range will include[-(p - 1)/2, (p - 1)/2].
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.
Implementations on Foreign Types§
Source§impl<FP> QuotientMap<i8> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<i8> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: i8) -> MontyField31<FP>
fn from_int(int: i8) -> MontyField31<FP>
Convert a given i8 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§fn from_canonical_checked(int: i8) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: i8) -> Option<MontyField31<FP>>
Convert a given i8 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§unsafe fn from_canonical_unchecked(int: i8) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: i8) -> MontyField31<FP>
Convert a given i8 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§impl<FP> QuotientMap<i16> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<i16> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: i16) -> MontyField31<FP>
fn from_int(int: i16) -> MontyField31<FP>
Convert a given i16 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§fn from_canonical_checked(int: i16) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: i16) -> Option<MontyField31<FP>>
Convert a given i16 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§unsafe fn from_canonical_unchecked(int: i16) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: i16) -> MontyField31<FP>
Convert a given i16 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§impl<FP> QuotientMap<i32> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<i32> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: i32) -> MontyField31<FP>
fn from_int(int: i32) -> MontyField31<FP>
Convert a given i32 integer into an element of the MontyField31 field.
Source§fn from_canonical_checked(int: i32) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: i32) -> Option<MontyField31<FP>>
Convert a given i32 integer into an element of the MontyField31 field.
Returns None if the given integer does not lie in the range [(1 - P)/2, (P - 1)/2].
Source§unsafe fn from_canonical_unchecked(int: i32) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: i32) -> MontyField31<FP>
Convert a given i32 integer into an element of the MontyField31 field.
§Safety
This is always safe as the conversion to monty form can accept any i32.
Source§impl<FP> QuotientMap<i64> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<i64> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: i64) -> MontyField31<FP>
fn from_int(int: i64) -> MontyField31<FP>
Convert a given i64 integer into an element of the MontyField31 field.
Source§fn from_canonical_checked(int: i64) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: i64) -> Option<MontyField31<FP>>
Convert a given i64 integer into an element of the MontyField31 field.
Returns None if the given integer does not lie in the range [(1 - P)/2, (P - 1)/2].
Source§unsafe fn from_canonical_unchecked(int: i64) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: i64) -> MontyField31<FP>
Convert a given i64 integer into an element of the MontyField31 field.
§Safety
This is always safe as the conversion to monty form can accept any i64.
Source§impl<FP> QuotientMap<i128> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<i128> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: i128) -> MontyField31<FP>
fn from_int(int: i128) -> MontyField31<FP>
Convert a given i128 integer into an element of the MontyField31 field.
Source§fn from_canonical_checked(int: i128) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: i128) -> Option<MontyField31<FP>>
Convert a given i128 integer into an element of the MontyField31 field.
Returns None if the given integer does not lie in the range [(1 - P)/2, (P - 1)/2].
Source§unsafe fn from_canonical_unchecked(int: i128) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: i128) -> MontyField31<FP>
Convert a given i128 integer into an element of the MontyField31 field.
§Safety
The input must be a valid i64 element.
Source§impl<FP> QuotientMap<u8> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<u8> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: u8) -> MontyField31<FP>
fn from_int(int: u8) -> MontyField31<FP>
Convert a given u8 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§fn from_canonical_checked(int: u8) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: u8) -> Option<MontyField31<FP>>
Convert a given u8 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§unsafe fn from_canonical_unchecked(int: u8) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: u8) -> MontyField31<FP>
Convert a given u8 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§impl<FP> QuotientMap<u16> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<u16> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: u16) -> MontyField31<FP>
fn from_int(int: u16) -> MontyField31<FP>
Convert a given u16 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§fn from_canonical_checked(int: u16) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: u16) -> Option<MontyField31<FP>>
Convert a given u16 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§unsafe fn from_canonical_unchecked(int: u16) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: u16) -> MontyField31<FP>
Convert a given u16 integer into an element of the MontyField31 field.
Due to the integer type, the input value is always canonical.
Source§impl<FP> QuotientMap<u32> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<u32> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: u32) -> MontyField31<FP>
fn from_int(int: u32) -> MontyField31<FP>
Convert a given u32 integer into an element of the MontyField31 field.
Source§fn from_canonical_checked(int: u32) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: u32) -> Option<MontyField31<FP>>
Convert a given u32 integer into an element of the MontyField31 field.
Returns None if the given integer is greater than the Prime.
Source§unsafe fn from_canonical_unchecked(int: u32) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: u32) -> MontyField31<FP>
Convert a given u32 integer into an element of the MontyField31 field.
§Safety
This is always safe as the conversion to monty form can accept any u32.
Source§impl<FP> QuotientMap<u64> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<u64> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: u64) -> MontyField31<FP>
fn from_int(int: u64) -> MontyField31<FP>
Convert a given u64 integer into an element of the MontyField31 field.
Source§fn from_canonical_checked(int: u64) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: u64) -> Option<MontyField31<FP>>
Convert a given u64 integer into an element of the MontyField31 field.
Returns None if the given integer is greater than the Prime.
Source§unsafe fn from_canonical_unchecked(int: u64) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: u64) -> MontyField31<FP>
Convert a given u64 integer into an element of the MontyField31 field.
§Safety
This is always safe as the conversion to monty form can accept any u64.
Source§impl<FP> QuotientMap<u128> for MontyField31<FP>where
FP: FieldParameters,
impl<FP> QuotientMap<u128> for MontyField31<FP>where
FP: FieldParameters,
Source§fn from_int(int: u128) -> MontyField31<FP>
fn from_int(int: u128) -> MontyField31<FP>
Convert a given u128 integer into an element of the MontyField31 field.
Source§fn from_canonical_checked(int: u128) -> Option<MontyField31<FP>>
fn from_canonical_checked(int: u128) -> Option<MontyField31<FP>>
Convert a given u128 integer into an element of the MontyField31 field.
Returns None if the given integer is greater than the Prime.
Source§unsafe fn from_canonical_unchecked(int: u128) -> MontyField31<FP>
unsafe fn from_canonical_unchecked(int: u128) -> MontyField31<FP>
Convert a given u128 integer into an element of the MontyField31 field.
§Safety
The input must be a valid u64 element.