Crates.io | alloy-primitives |
lib.rs | alloy-primitives |
version | |
source | src |
created_at | 2023-06-13 06:27:50.29651 |
updated_at | 2024-12-09 12:43:07.753042 |
description | Ethereum primitive types |
homepage | https://github.com/alloy-rs/core/tree/main/crates/primitives |
repository | https://github.com/alloy-rs/core |
max_upload_size | |
id | 888733 |
Cargo.toml error: | TOML parse error at line 20, column 1 | 20 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
use alloy_primitives::{address, fixed_bytes, Address, FixedBytes, I256, U256};
// FixedBytes
let n: FixedBytes<6> = fixed_bytes!("1234567890ab");
assert_eq!(n, "0x1234567890ab".parse::<FixedBytes<6>>().unwrap());
assert_eq!(n.to_string(), "0x1234567890ab");
// Uint
let mut n: U256 = "42".parse().unwrap();
n += U256::from(10);
assert_eq!(n.to_string(), "52");
// Signed
let mut n: I256 = "-42".parse().unwrap();
n = -n;
assert_eq!(n.to_string(), "42");
// Address
let addr_str = "0x66f9664f97F2b50F62D13eA064982f936dE76657";
let addr: Address = Address::parse_checksummed(addr_str, None).unwrap();
assert_eq!(addr, address!("66f9664f97F2b50F62D13eA064982f936dE76657"));
assert_eq!(addr.to_checksum(None), addr_str);
// Address checksummed with a custom chain id
let addr_str = "0x66F9664f97f2B50F62d13EA064982F936de76657";
let addr: Address = Address::parse_checksummed(addr_str, Some(30)).unwrap();
assert_eq!(addr, address!("66F9664f97f2B50F62d13EA064982F936de76657"));
assert_eq!(addr.to_checksum(Some(30)), addr_str);