#fixed-hash #fixed-size #tetsy #macro #byte #type #h256

no-std tetsy-fixed-hash

Macros to define custom tetsy-fixed-size hash types

Show the crate…

4 releases

0.7.1 Jun 8, 2021
0.7.0 Feb 18, 2021
0.7.0-alpha Mar 10, 2021
0.5.0 Feb 20, 2021

#2 in #tetsy

Download history 311/week @ 2024-05-21 345/week @ 2024-05-28 269/week @ 2024-06-04 204/week @ 2024-06-11 390/week @ 2024-06-18 295/week @ 2024-06-25 29/week @ 2024-07-02 263/week @ 2024-07-09 368/week @ 2024-07-16 261/week @ 2024-07-23 342/week @ 2024-07-30 253/week @ 2024-08-06 252/week @ 2024-08-13 252/week @ 2024-08-20 395/week @ 2024-08-27 191/week @ 2024-09-03

1,109 downloads per month
Used in 233 crates (3 directly)

MIT/Apache

38KB
846 lines

Fixed Hash

Provides macros to construct custom fixed-size hash types.

Examples

Simple 256 bit (32 bytes) hash type.

use tetsy_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);
}

Features

By default this is an standard library depending crate. For a #[no_std] environment use it as follows:

tetsy-fixed-hash = { version = "0.3", default-features = false }

Available Features

  • std: Use the standard library instead of the core library.
    • Using this feature enables the following features
      • rustc-hex/std
      • rand/std
      • byteorder/std
    • Enabled by default.
  • libc: Use libc for implementations of PartialEq and Ord.
    • Enabled by default.
  • rand: Provide API based on the rand crate.
    • Enabled by default.
  • byteorder: Provide API based on the byteorder crate.
    • Enabled by default.
  • quickcheck: Provide quickcheck implementation for hash types.
    • Disabled by default.
  • api-dummy: Generate a dummy hash type for API documentation.
    • Enabled by default at docs.rs
  • arbitrary: Allow for creation of a hash from random unstructured input.
    • Disabled by default.

Dependencies

~0.4–0.9MB
~15K SLoC