14 releases

0.3.0 Nov 12, 2018
0.3.0-beta.1 Oct 31, 2018
0.2.1 Apr 11, 2018
0.2.0 Mar 15, 2018
0.1.0 Dec 29, 2017

#1 in Cryptocurrencies

Download history 1899/week @ 2018-10-17 2412/week @ 2018-10-24 2928/week @ 2018-10-31 3737/week @ 2018-11-07 3875/week @ 2018-11-14 2960/week @ 2018-11-21 3879/week @ 2018-11-28 4341/week @ 2018-12-05 3856/week @ 2018-12-12 3012/week @ 2018-12-19 2474/week @ 2018-12-26 3898/week @ 2019-01-02 3563/week @ 2019-01-09 2905/week @ 2019-01-16 3081/week @ 2019-01-23

13,367 downloads per month
Used in 33 crates (5 directly)

MIT license

38KB
946 lines

Fixed Hash

Provides macros to construct custom fixed-size hash types.

Examples

Simple 256 bit (32 bytes) hash type.

#[macro_use] extern crate 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.

extern crate serde;
#[macro_use] extern crate serde_derive;

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:

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.
  • heapsize: Provide HeapsizeOf implementation for hash types.
    • Disabled 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

Dependencies

~1MB
~11K SLoC