Primitive types shared by [alloy], [foundry], [revm], and [reth].
ruint
integersFixedBytes
]
wrap_fixed_bytes!
]: macro for constructing named fixed bytes typesAddress
], which is a fixed-size byte array of 20 bytes, with EIP-55 and
EIP-1191 checksum supportfixed_bytes!
], [address!
] and other macros to construct the types at
compile timeThis library has straightforward, basic, types. Usage is correspondingly simple. Please consult the documentation for more information.
```rust use alloyprimitives::{address, fixedbytes, Address, FixedBytes, I256, U256};
// FixedBytes
let n: FixedBytes<6> = fixedbytes!("1234567890ab");
asserteq!(n, "0x1234567890ab".parse::
// Uint let mut n: U256 = "42".parse().unwrap(); n += U256::from(10); asserteq!(n.tostring(), "52");
// Signed let mut n: I256 = "-42".parse().unwrap(); n = -n; asserteq!(n.tostring(), "42");
// Address let addrstr = "0x66f9664f97F2b50F62D13eA064982f936dE76657"; let addr: Address = Address::parsechecksummed(addrstr, None).unwrap(); asserteq!(addr, address!("66f9664f97F2b50F62D13eA064982f936dE76657")); asserteq!(addr.tochecksum(None), addr_str);
// Address checksummed with a custom chain id let addrstr = "0x66F9664f97f2B50F62d13EA064982F936de76657"; let addr: Address = Address::parsechecksummed(addrstr, Some(30)).unwrap(); asserteq!(addr, address!("66F9664f97f2B50F62d13EA064982F936de76657")); asserteq!(addr.tochecksum(Some(30)), addr_str); ```