1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! This crate implements 256-bit integer types.
//!
//! The implementation tries to follow as closely as possible to primitive
//! integer types, and should implement all the common methods and traits as the
//! primitive integer types.
extern crate alloc;
/// Macro for 256-bit signed integer literal.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # use ethnum::{int, I256};
/// assert_eq!(
/// int!(
/// "-57896044618658097711785492504343953926634992332820282019728792003956564819968"
/// ),
/// I256::MIN,
/// );
/// ```
///
/// Additionally, this macro accepts `0b` for binary, `0o` for octal, and `0x`
/// for hexadecimal literals. Using `_` for spacing is also permitted.
///
/// ```
/// # use ethnum::{int, I256};
/// assert_eq!(
/// int!(
/// "0x7fff_ffff_ffff_ffff_ffff_ffff_ffff_ffff
/// ffff_ffff_ffff_ffff_ffff_ffff_ffff_ffff"
/// ),
/// I256::MAX,
/// );
/// assert_eq!(int!("0b101010"), 42);
/// assert_eq!(int!("-0o52"), -42);
/// ```
/// Macro for 256-bit unsigned integer literal.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # use ethnum::{uint, U256};
/// assert_eq!(
/// uint!(
/// "115792089237316195423570985008687907852837564279074904382605163141518161494337"
/// ),
/// U256::from_words(
/// 0xfffffffffffffffffffffffffffffffe,
/// 0xbaaedce6af48a03bbfd25e8cd0364141,
/// ),
/// );
/// ```
///
/// Additionally, this macro accepts `0b` for binary, `0o` for octal, and `0x`
/// for hexadecimal literals. Using `_` for spacing is also permitted.
///
/// ```
/// # use ethnum::{uint, U256};
/// assert_eq!(
/// uint!(
/// "0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ffff
/// ffff_ffff_ffff_ffff_ffff_ffff_ffff_ffff"
/// ),
/// U256::MAX,
/// );
/// assert_eq!(uint!("0b101010"), 42);
/// assert_eq!(uint!("0o52"), 42);
/// ```
/// Module containing required re-exports for macros.
///
/// This "trick" allows us to export declarative macros that wrap the inner
/// procedural macro implementations, without requiring the `ethnum` crate to
/// be available in the invocation context. This means that the macros continue
/// to work even when the crate is renamed, or the macro is re-exported.
/// Convenience re-export of 256-integer types and as- conversion traits.
pub use crate::;
/// A 256-bit signed integer type.
pub type i256 = I256;
/// A 256-bit unsigned integer type.
pub type u256 = U256;