[−][src]Attribute Macro modtype_derive::use_modtype
#[use_modtype]
An attribute macro to use a modular arithmetic type with a ConstValue
argument.
This macro:
- Confirms that the type contains 1 const argument.
- Creates a bottom type that represents the const value.
- Implements
ConstValue
for the bottom type. - Replaces the const argument with the bottom type.
- 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
Name | Format | Optional |
---|---|---|
constant | constant($ Ident ) | Yes (default = concat!(_, $value, $type_pascal_case) ) |
constructor | constructor($ Ident ) | Yes (default = the type alias) |