macro_rules! int_type_doc {
($bits: literal, $sign: literal, $aliased: literal) => {
concat!(
$bits, "-bit ", $sign, " integer type.",
"\n\n",
"Overflow behaviour is the same as that of the primitive integer types, i.e. wrap on overflow if `overflow-checks` are disabled and panic on overflow if `overflow-checks` are enabled.",
"\n\n",
"This type is an alias of [`", $aliased, "`](crate::", $aliased, "). See the documentation of [`", $aliased, "`](crate::", $aliased, ") for available methods and behaviour details."
)
};
}
macro_rules! int_types {
{ $($bits: literal $u: ident $i: ident; ) *} => {
$(
#[doc = int_type_doc!($bits, "unsigned", "Uint")]
pub type $u = crate::Uint::<{ crate::literal_parse::get_size_params_from_bits($bits).0 }, { crate::literal_parse::get_size_params_from_bits($bits).1 }>;
#[doc = int_type_doc!($bits, "signed", "Int")]
pub type $i = crate::Int::<{ crate::literal_parse::get_size_params_from_bits($bits).0 }, { crate::literal_parse::get_size_params_from_bits($bits).1 }>;
)*
};
}
macro_rules! call_types_macro {
($name: ident) => {
$name! {
128 U128 I128;
256 U256 I256;
512 U512 I512;
1024 U1024 I1024;
2048 U2048 I2048;
4096 U4096 I4096;
8192 U8192 I8192;
}
};
}
call_types_macro!(int_types);
#[cfg(test)]
mod tests {
use super::*;
macro_rules! assert_int_bits {
{ $($bits: literal $u: ident $i: ident; ) *} => {
$(
assert_eq!($u::BITS, $bits);
assert_eq!($i::BITS, $bits);
)*
}
}
#[test]
fn test_int_bits() {
call_types_macro!(assert_int_bits);
}
}