numext_fixed_uint/
lib.rs

1// Copyright 2018-2019 Cryptape Technologies LLC.
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//! A series of fixed non-negative integer types.
10//!
11//! # Constructors
12//!
13//! This crate provides a series of macros that used to construct fixed uints in compile time.
14//!
15//! The input is a string literal, and the macros support several formats of the input:
16//! - A decimal string.
17//! - A binary string with `0b` prefix.
18//! - A octal string with `0o` prefix.
19//! - A hexadecimal string with `0x` prefix.
20//!
21//! And you can use any number of `_` in the string literal to separate it for more readable.
22//!
23//! ## Examples
24//!
25//! ```rust
26//! use numext_fixed_uint::{u128, U128};
27//!
28//! const U128_100: U128 = u128!("100");
29//!
30//! fn main () -> ::std::io::Result<()> {
31//!     let x1 = u128!("0b110_0100");
32//!     let x2 = u128!("0o144");
33//!     let x3 = u128!("0x64");
34//!     let y = U128::from(100u8);
35//!     assert_eq!(x1, y);
36//!     assert_eq!(x2, y);
37//!     assert_eq!(x3, y);
38//!     assert_eq!(U128_100, y);
39//!     Ok(())
40//! }
41//! ```
42
43extern crate nfuint_core;
44extern crate nfuint_hack;
45
46pub use nfuint_core::prelude;
47pub use nfuint_core::{FixedUintError, FromSliceError, FromStrError, IntoSliceError};
48
49macro_rules! reexport {
50    ([$(($name:ident, $macro_name:ident),)+]) => {
51        $(reexport!($name, $macro_name);)+
52    };
53    ([$(($name:ident, $macro_name:ident)),+]) => {
54        $(reexport!($name, $macro_name);)+
55    };
56    ($name:ident, $macro_name:ident) =>    {
57        pub use nfuint_core::$name;
58        /// A macro used to construct a fixed uint in compile time.
59        pub use nfuint_hack::$macro_name;
60    };
61}
62
63reexport!([
64    (U128, u128),
65    (U160, u160),
66    (U224, u224),
67    (U256, u256),
68    (U384, u384),
69    (U512, u512),
70    (U520, u520),
71    (U1024, u1024),
72    (U2048, u2048),
73    (U4096, u4096),
74]);