tetsy_impl_num_traits/
lib.rs

1// Copyright 2020 Parity Technologies
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9//! num-traits support for uint.
10
11#![no_std]
12
13#[doc(hidden)]
14pub use num_traits;
15
16#[doc(hidden)]
17pub use uint_crate;
18
19/// Add num-traits support to an integer created by `construct_uint!`.
20#[macro_export]
21macro_rules! impl_uint_num_traits {
22	($name: ident, $len: expr) => {
23		impl $crate::tetsy_num_traits::identities::Zero for $name {
24			#[inline]
25			fn zero() -> Self {
26				Self::zero()
27			}
28
29			#[inline]
30			fn is_zero(&self) -> bool {
31				self.is_zero()
32			}
33		}
34
35		impl $crate::tetsy_num_traits::identities::One for $name {
36			#[inline]
37			fn one() -> Self {
38				Self::one()
39			}
40		}
41
42		impl $crate::tetsy_num_traits::Num for $name {
43			type FromStrRadixErr = $crate::uint_crate::FromStrRadixErr;
44
45			fn from_str_radix(txt: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
46				Self::from_str_radix(txt, radix)
47			}
48		}
49	};
50}