8 releases (stable)
1.2.1 | Jan 27, 2023 |
---|---|
1.2.0 | Jul 22, 2022 |
1.1.2 | May 26, 2022 |
1.1.0 | Oct 17, 2021 |
0.1.0 | Jun 17, 2021 |
#7 in #u256
2,866 downloads per month
Used in 19 crates
(2 directly)
6KB
58 lines
u256-literal
Description
This crate helps you to declare a constant U256
in an easy way. No need to wrap the integer literal around double quotes.
Usage
use primitive_types::U256;
use u256_literal::u256;
const Q96: U256 = u256!(0x1000000000000000000000000);
// support hex style integer
let x = u256!(0x1234ff);
// support normal style
let y = u256!(987654);
// support float style number
let z = u256!(1.23e18);
License
All crates licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
This crate provides u256!
macro for converting u256 literals to actual primitive_types::U256
at compile time.
This is helpful when you're trying to define a const U256.
It supports 0x
prefix and normal decimals. When the number is too large to fit into U256, it would complain.
This crate assumes you have primitive-types
added to your Cargo.toml
dependency.
Examples
let x = u256!(123454444444444444444444444444444444444444444);
let y = u256!(0x123456789827823721235568483);
let z = u256!(1e18);
let w = u256!(1.23e18);
Dependencies
~2MB
~42K SLoC