-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Num from num-traits (#480)
- Loading branch information
Showing
7 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "impl-num-traits" | ||
version = "0.1.0" | ||
authors = ["Parity Technologies <admin@parity.io>"] | ||
license = "MIT OR Apache-2.0" | ||
homepage = "https://github.com/paritytech/parity-common" | ||
description = "num-traits implementation for uint." | ||
edition = "2018" | ||
|
||
[dependencies] | ||
num-traits = { version = "0.2", default-features = false } | ||
uint = { version = "0.8.5", path = "../../../uint", default-features = false } | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["num-traits/std", "uint/std"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2020 Parity Technologies | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! num-traits support for uint. | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
#[doc(hidden)] | ||
pub use num_traits; | ||
|
||
pub use uint::{FromStrRadixErr, FromStrRadixErrKind}; | ||
|
||
/// Add num-traits support to an integer created by `construct_uint!`. | ||
#[macro_export] | ||
macro_rules! impl_uint_num_traits { | ||
($name: ident, $len: expr) => { | ||
impl $crate::num_traits::identities::Zero for $name { | ||
#[inline] | ||
fn zero() -> Self { | ||
Self::zero() | ||
} | ||
|
||
#[inline] | ||
fn is_zero(&self) -> bool { | ||
self.is_zero() | ||
} | ||
} | ||
|
||
impl $crate::num_traits::identities::One for $name { | ||
#[inline] | ||
fn one() -> Self { | ||
Self::one() | ||
} | ||
} | ||
|
||
impl $crate::num_traits::Num for $name { | ||
type FromStrRadixErr = $crate::FromStrRadixErr; | ||
|
||
fn from_str_radix(txt: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> { | ||
Self::from_str_radix(txt, radix) | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters