#literals #u256 #proc-macro #ethereum #compile-time

macro u256-literal

Procedural macro for converting u256 literals to U256 at compile time

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

#9 in #u256

Download history 61/week @ 2024-06-05 95/week @ 2024-06-12 251/week @ 2024-06-19 279/week @ 2024-06-26 617/week @ 2024-07-03 503/week @ 2024-07-10 678/week @ 2024-07-17 857/week @ 2024-07-24 1008/week @ 2024-07-31 1512/week @ 2024-08-07 2380/week @ 2024-08-14 1451/week @ 2024-08-21 1341/week @ 2024-08-28 1845/week @ 2024-09-04 2116/week @ 2024-09-11 1228/week @ 2024-09-18

6,650 downloads per month
Used in 19 crates (2 directly)

MIT/Apache

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

~1.5MB
~41K SLoC