type_hash 0.3.0

Generate a hash for a Rust type. The primary use-case for this crate is for detecting differences in message types between versions of a crate. The `TypeHash` trait is implemented for most built-in types and a derive macro is provided, for implementing it for your own types.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use type_hash::TypeHash;

#[derive(TypeHash)]
#[allow(unused)]
enum Foo<A, B> {
    A(A),
    B(Vec<B>),
}

#[test]
fn different_generic_args_give_different_hashes() {
    assert_ne!(Foo::<i32, bool>::type_hash(), Foo::<i32, u64>::type_hash())
}

#[test]
fn same_generic_args_give_same_hashes() {
    assert_eq!(Foo::<i32, bool>::type_hash(), Foo::<i32, bool>::type_hash())
}