Struct cryptix_field::Element

source ·
pub struct Element<I, M: Modular<I>>(pub I, _);
Expand description

An element in mod n ring, the type parameter I should be an integer the modular p is embedded in the type parameter M, it’s typically a ZST

Tuple Fields§

§0: I

Implementations§

source§

impl<I, M: Modular<I>> Element<I, M>where I: Rem<Output = I>,

source

pub fn new(value: I) -> Self

source§

impl<I, M: Modular<I>> Element<I, M>

source

pub const fn new_unchecked(value: I) -> Self

Safety

This function is designed to be used in const environment to directly convert a canonical representative into mod p field element. So we made an assumption that the parameter value must lie between 0 to p - 1. Creating a field element with non-canonical representative can lead to unexpected result when computing

source§

impl<I, M: Modular<I>> Element<I, M>

source

pub const fn repr(&self) -> &I

value of the representative

source

pub const fn modular() -> I

Trait Implementations§

source§

impl<I, M> Add<Element<I, M>> for Element<I, M>where M: Modular<I>, I: BigIntOps,

§

type Output = Element<I, M>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<I, M> AddIdentity for Element<I, M>where M: Modular<I>, I: BigIntOps + IsBigInt,

source§

const ADD_IDENTITY: Self = _

the identity of mod add operation, typically zero
source§

const ZERO: Self = Self::ADD_IDENTITY

source§

impl<I: Copy, M: Modular<I>> Clone for Element<I, M>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<I: Debug, M: Modular<I>> Debug for Element<I, M>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<I, M: PrimeModular<I>> From<FpElement<I, M>> for Element<I, M>

source§

fn from(value: FpElement<I, M>) -> Self

Converts to this type from the input type.
source§

impl<I, M: Modular<I>> From<I> for Element<I, M>where I: Rem<Output = I>,

source§

fn from(value: I) -> Self

convert a integer to a mod p field element, this value will be converted into the canonical representative

source§

impl<I, M> Mul<Element<I, M>> for Element<I, M>where M: Modular<I>, I: BigIntOpsExt,

source§

fn mul(self, rhs: Self) -> Self::Output

calculate a * b mod m this can be achieved more efficiently with montgomery multiplication

§

type Output = Element<I, M>

The resulting type after applying the * operator.
source§

impl<I, M> Neg for Element<I, M>where M: Modular<I>, Self: Sub<Output = Self> + AddIdentity,

§

type Output = Element<I, M>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<I: Ord, M: Modular<I>> Ord for Element<I, M>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<I: PartialEq, M: Modular<I>> PartialEq<Element<I, M>> for Element<I, M>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<I: PartialOrd, M: Modular<I>> PartialOrd<Element<I, M>> for Element<I, M>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<I, M> Sub<Element<I, M>> for Element<I, M>where M: Modular<I>, I: BigIntOps,

§

type Output = Element<I, M>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl<I, M> AbelianGroup for Element<I, M>where M: Modular<I>, Self: Group + CommunicativeAdd,

source§

impl<I, M> AssociativeAdd for Element<I, M>where M: Modular<I>, Self: Add<Output = Self>,

Safety

Element is backed by biguint, which is associative under addition

source§

impl<I, M> AssociativeMul for Element<I, M>where M: Modular<I>, Self: Mul<Output = Self>,

Safety

our element type is backed by biguint, so mod mul is associative

source§

impl<I, M> CommunicativeAdd for Element<I, M>where M: Modular<I>, Self: Add<Output = Self>,

Safety

Element is backed by biguint, which is communicative under addition

source§

impl<I: Copy, M: Modular<I>> Copy for Element<I, M>

source§

impl<I, M> DistributiveMul for Element<I, M>where M: Modular<I>, Self: Mul<Output = Self> + Add<Output = Self>,

Safety

our element type is backed by biguint, so mod mul is distributive over add

source§

impl<I: Eq, M: Modular<I>> Eq for Element<I, M>

source§

impl<I, M> Group for Element<I, M>where M: Modular<I>, I: BigIntOps,

source§

impl<I, M> Ring for Element<I, M>where M: Modular<I>, Self: Mul<Output = Self> + AssociativeMul + DistributiveMul + AbelianGroup,

Auto Trait Implementations§

§

impl<I, M> RefUnwindSafe for Element<I, M>where I: RefUnwindSafe, M: RefUnwindSafe,

§

impl<I, M> Send for Element<I, M>where I: Send, M: Send,

§

impl<I, M> Sync for Element<I, M>where I: Sync, M: Sync,

§

impl<I, M> Unpin for Element<I, M>where I: Unpin, M: Unpin,

§

impl<I, M> UnwindSafe for Element<I, M>where I: UnwindSafe, M: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.