[][src]Attribute Macro modtype_derive::use_modtype

#[use_modtype]

An attribute macro to use a modular arithmetic type with a ConstValue argument.

This macro:

  1. Confirms that the type contains 1 const argument.
  2. Creates a bottom type that represents the const value.
  3. Implements ConstValue for the bottom type.
  4. Replaces the const argument with the bottom type.
  5. Creates a pseudo constructor.

Usage

// #[modtype::use_modtype(constant(_1000000007U64), constructor(F))]
#[modtype::use_modtype]
type F = modtype::F<1_000_000_007u64>;

assert_eq!((F(1_000_000_006) + F(2)).to_string(), "1");

type F = modtype::F<_1000000007U64>;

enum _1000000007U64 {}

impl ::modtype::ConstValue for _1000000007U64 {
    type Value = u64;
    const VALUE: u64 = 1_000_000_007u64;
}

#[allow(non_snake_case)]
#[inline]
fn F(value: u64) -> F {
    F::new(value)
}

assert_eq!((F(1_000_000_006) + F(2)).to_string(), "1");

Attributes

NameFormatOptional
constantconstant($Ident)Yes (default = concat!(_, $value, $type_pascal_case))
constructorconstructor($Ident)Yes (default = the type alias)