Crates.io | ethers-fixed-hash |
lib.rs | ethers-fixed-hash |
version | 0.8.0 |
source | src |
created_at | 2023-01-28 10:53:13.383614 |
updated_at | 2023-01-28 10:53:13.383614 |
description | Macros to define custom fixed-size hash types |
homepage | https://github.com/paritytech/parity-common |
repository | https://github.com/paritytech/parity-common |
max_upload_size | |
id | 770300 |
size | 52,101 |
Provides macros to construct custom fixed-size hash types.
Simple 256 bit (32 bytes) hash type.
use fixed_hash::construct_fixed_hash;
construct_fixed_hash! {
/// My 256 bit hash type.
pub struct H256(32);
}
Opt-in to add conversions between differently sized hashes.
construct_fixed_hash!{ struct H256(32); }
construct_fixed_hash!{ struct H160(20); }
// auto-implement conversions between H256 and H160
impl_fixed_hash_conversions!(H256, H160);
// now use the generated conversions
assert_eq!(H256::from(H160::zero()), H256::zero());
assert_eq!(H160::from(H256::zero()), H160::zero());
It is possible to add attributes to your types, for example to make them serializable.
construct_fixed_hash!{
/// My serializable hash type.
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
struct H160(20);
}
By default this is an standard library depending crate.
For a #[no_std]
environment use it as follows:
fixed-hash = { version = "0.3", default-features = false }
std
: Use the standard library instead of the core library.
rustc-hex/std
rand/std
byteorder/std
libc
: Use libc
for implementations of PartialEq
and Ord
.
rand
: Provide API based on the rand
crate.
byteorder
: Provide API based on the byteorder
crate.
quickcheck
: Provide quickcheck
implementation for hash types.
api-dummy
: Generate a dummy hash type for API documentation.
docs.rs
arbitrary
: Allow for creation of a hash from random unstructured input.