ethers_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 integer_sqrt;
18
19#[doc(hidden)]
20pub use uint;
21
22/// Add num-traits support to an integer created by `construct_uint!`.
23#[macro_export]
24macro_rules! impl_uint_num_traits {
25	($name: ident, $len: expr) => {
26		impl $crate::num_traits::sign::Unsigned for $name {}
27
28		impl $crate::num_traits::identities::Zero for $name {
29			#[inline]
30			fn zero() -> Self {
31				Self::zero()
32			}
33
34			#[inline]
35			fn is_zero(&self) -> bool {
36				self.is_zero()
37			}
38		}
39
40		impl $crate::num_traits::identities::One for $name {
41			#[inline]
42			fn one() -> Self {
43				Self::one()
44			}
45		}
46
47		impl $crate::num_traits::Num for $name {
48			type FromStrRadixErr = $crate::uint::FromStrRadixErr;
49
50			fn from_str_radix(txt: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
51				Self::from_str_radix(txt, radix)
52			}
53		}
54
55		impl $crate::integer_sqrt::IntegerSquareRoot for $name {
56			fn integer_sqrt_checked(&self) -> Option<Self> {
57				Some(self.integer_sqrt())
58			}
59		}
60	};
61}