sosecrets_rs/
macros.rs

1#[cfg(feature = "cloneable-secret")]
2macro_rules! impl_cloneable_secret_for_numbers {
3    ($($t:ty),*) => {
4        $(
5            impl $crate::traits::CloneableSecret for $t {}
6        )*
7    };
8}
9
10#[cfg(feature = "cloneable-secret")]
11pub(crate) use impl_cloneable_secret_for_numbers;
12
13#[cfg(feature = "debug-secret")]
14macro_rules! impl_debug_secret_for_numbers {
15    ($($t:ty),*) => {
16        $(
17            impl $crate::traits::DebugSecret for $t {}
18        )*
19    };
20}
21
22#[cfg(feature = "debug-secret")]
23pub(crate) use impl_debug_secret_for_numbers;
24
25macro_rules! impl_sealed_trait_for_uint {
26    ($($t:ty),*) => {
27        $(
28            impl $crate::traits::__private::SealedTrait for $t {}
29        )*
30    };
31}
32pub(crate) use impl_sealed_trait_for_uint;
33
34macro_rules! impl_choose_int {
35    // Entry point
36    ($($arg:ident => $out:ty;)*) => {
37        impl_choose_int! {
38            @prev_args ();
39            @prev_num $crate::prelude::typenum::UTerm;
40            @rest_args ($($arg,)*);
41            @rest_out ($($out;)*);
42        }
43    };
44
45    // Implement one
46    (
47        @prev_args ($($prev_args:ident,)*);
48        @prev_num $prev_num:ty;
49        @rest_args ($arg:ident, $($rest_args:ident,)*);
50        @rest_out ($out:ty; $($rest_out:ty;)*);
51    )
52    => {
53        impl<$($prev_args,)* $arg> $crate::traits::__private::SealedTrait for $crate::prelude::typenum::uint::UInt<$prev_num, $arg> {}
54
55        impl<$($prev_args,)* $arg> $crate::traits::ChooseMinimallyRepresentableUInt for $crate::prelude::typenum::uint::UInt<$prev_num, $arg> {
56            type Output = $out;
57            type AtomicOutput = <$out as $crate::traits::AsAtomic>::Output;
58            const ZERO: Self::Output = Self::Output::MIN;
59            const ONE: Self::Output = 1;
60
61            fn cast_unsigned_to_self_type<T: $crate::prelude::typenum::uint::Unsigned>(_: $crate::traits::__private::SealedToken) -> Self::Output {
62                <T as $crate::prelude::typenum::uint::Unsigned>::USIZE as Self::Output
63            }
64        }
65
66        impl_choose_int!{
67            @prev_args ($($prev_args,)* $arg,);
68            @prev_num $crate::prelude::typenum::uint::UInt<$prev_num, $arg>;
69            @rest_args ($($rest_args,)*);
70            @rest_out ($($rest_out;)*);
71        }
72    };
73
74    // Base case; stop iteration
75    (
76        @prev_args ($($prev_args:ident,)*);
77        @prev_num $prev_num:ty;
78        @rest_args ();
79        @rest_out ();
80    ) => {};
81}
82
83pub(crate) use impl_choose_int;