#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 99/week @ 2023-12-11 120/week @ 2023-12-18 51/week @ 2023-12-25 115/week @ 2024-01-01 147/week @ 2024-01-08 148/week @ 2024-01-15 124/week @ 2024-01-22 142/week @ 2024-01-29 116/week @ 2024-02-05 145/week @ 2024-02-12 85/week @ 2024-02-19 132/week @ 2024-02-26 120/week @ 2024-03-04 134/week @ 2024-03-11 127/week @ 2024-03-18 117/week @ 2024-03-25

500 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
~39K SLoC