#![allow(dead_code)] #[derive(udigest::Digestable)] #[udigest(tag = concat!("udigest.example", ".v1"))] pub struct DigestableExample { pub some_string: String, pub integer: u64, pub list: Vec, #[udigest(as_bytes)] pub bytes: [u8; 10], #[udigest(as_bytes = SomeValue::as_bytes)] #[udigest(rename = "more more bytes")] pub more_bytes: SomeValue, #[udigest(as_bytes = SomeValue::to_vec)] pub bytes_as_vec: SomeValue, #[udigest(skip)] pub ignored_field: Empty, } pub struct SomeValue(Vec); impl SomeValue { pub fn as_bytes(&self) -> &[u8] { &self.0 } pub fn to_vec(&self) -> Vec { self.0.clone() } } pub struct Empty; #[derive(udigest::Digestable)] pub enum EnumExample { Variant1 { integer: i32, #[udigest(rename = 2_u32.to_be_bytes())] string: String, #[udigest(as_bytes = SomeValue::as_bytes)] something_else: SomeValue, }, Variant2(String, #[udigest(as_bytes)] Vec, #[udigest(skip)] Empty), Variant3 {}, Variant4(), Variant5, } #[derive(udigest::Digestable)] #[udigest(bound = "")] pub struct Bounds where D: Clone, { _ph: std::marker::PhantomData, } #[derive(udigest::Digestable)] pub enum EmptyEnum {} pub mod isolated { use ::udigest as udigest2; mod udigest {} #[derive(udigest2::Digestable)] #[udigest(root = udigest2)] pub struct Foo { bar: String, } } #[derive(udigest::Digestable)] #[udigest(tag = "udigest.example.v1")] pub enum EnumWithTag { Variant1(String), Variant2 { int: u32 }, } #[derive(udigest::Digestable)] pub struct StructAttrWith { #[udigest(with = encoding::encode_bar)] foo: Bar, } pub struct Bar; mod encoding { pub fn encode_bar( _bar: &super::Bar, encoder: udigest::encoding::EncodeValue, ) { let mut list = encoder.encode_list(); list.add_leaf().chain("foo"); list.add_leaf().chain("bar"); list.finish() } } #[derive(udigest::Digestable)] pub struct StructWithRefs<'a> { field1: &'a str, #[udigest(as_bytes)] field2: &'a [u8], field3: &'a String, #[udigest(with = encoding::encode_bar)] field4: &'a Bar, } #[derive(udigest::Digestable)] pub struct OptionalBytes { #[udigest(as = Option)] field1: Option>, #[udigest(as = std::collections::BTreeMap<_, udigest::Bytes>)] hash_map: std::collections::HashMap>, }