#[test] fn no_tag() { #[derive(udigest::Digestable)] struct Person { name: &'static str, age: u32, } let hash_expected = udigest::hash::(&Person { name: "Alice", age: 24, }); let hash_actual = udigest::hash::(&udigest::inline_struct!({ name: "Alice", age: 24_u32, })); assert_eq!(hex::encode(hash_expected), hex::encode(hash_actual)); } #[test] fn with_tag() { #[derive(udigest::Digestable)] #[udigest(tag = "some_tag")] struct Person { name: &'static str, age: u32, } let hash_expected = udigest::hash::(&Person { name: "Alice", age: 24, }); let hash_actual = udigest::hash::(&udigest::inline_struct!("some_tag" { name: "Alice", age: 24_u32, })); assert_eq!(hex::encode(hash_expected), hex::encode(hash_actual)); } #[test] fn embedded_structs() { #[derive(udigest::Digestable)] struct Person { name: &'static str, age: u32, preferences: Preferences, } #[derive(udigest::Digestable)] struct Preferences { display_email: bool, receive_newsletter: bool, } let hash_expected = udigest::hash::(&Person { name: "Alice", age: 24, preferences: Preferences { display_email: false, receive_newsletter: false, }, }); let hash_actual = udigest::hash::(&udigest::inline_struct!({ name: "Alice", age: 24_u32, preferences: udigest::inline_struct!({ display_email: false, receive_newsletter: false, }) })); assert_eq!(hex::encode(hash_expected), hex::encode(hash_actual)); } #[test] fn shorter_syntax() { let name = "Alice"; let age = 24_u32; let alice1 = udigest::inline_struct!({ name, age, }); let name = name.to_owned(); let alice2 = udigest::inline_struct!({ &name, age, }); assert_eq!( udigest::hash::(&alice1), udigest::hash::(&alice2), ); let _ = alice2; // `name` is not consumed drop(name); } #[test] fn impls_clone_copy() { fn impls_clone(_: &T) {} fn impls_copy(_: &T) {} let name = "Alice".to_owned(); let age = 24_u32; let alice = udigest::inline_struct!({ name, age, }); impls_clone(&alice); let name = "Alice"; let alice = udigest::inline_struct!({ name, age, }); impls_copy(&alice); }