Skip to main content

zinc_utils/
named.rs

1use crypto_primitives::{boolean::Boolean, crypto_bigint_int::Int, crypto_bigint_uint::Uint};
2
3pub trait Named {
4    /// Returns the name of the type as a string, used in benchmarks for nicer
5    /// output.
6    fn type_name() -> String;
7}
8
9//
10// Named implementations
11//
12
13macro_rules! impl_named_for_primitives {
14    ($($type:ty),+) => {
15        $(
16            impl Named for $type {
17                fn type_name() -> String {
18                    stringify!($type).to_string()
19                }
20            }
21        )+
22    };
23}
24
25impl_named_for_primitives!(i8, i16, i32, i64, i128);
26impl_named_for_primitives!(u8, u16, u32, u64, u128);
27
28impl<const LIMBS: usize> Named for Int<LIMBS> {
29    fn type_name() -> String {
30        format!("Int<{}>", LIMBS)
31    }
32}
33
34impl<const LIMBS: usize> Named for Uint<LIMBS> {
35    fn type_name() -> String {
36        format!("Uint<{}>", LIMBS)
37    }
38}
39
40impl Named for Boolean {
41    fn type_name() -> String {
42        "b".to_owned()
43    }
44}