mod serialize { use netherite::{assert_serialization, Serialize}; use std::mem::size_of; #[test] fn derive_empty() { #[derive(Serialize)] struct MyStruct {} } #[test] fn derive_fields() { #[derive(Serialize, Default)] struct MyStruct { field1: u32, field2: u16, unit: (), field3: u16, } let instance = MyStruct::default(); assert_eq!(instance.size(), size_of::()); assert_serialization!(instance => &[0; size_of::()]); } #[test] fn derive_generic() { #[derive(Serialize)] struct MyStruct { unit: T, } let instance = MyStruct { unit: 0u32 }; assert_eq!(instance.size(), std::mem::size_of::()); assert_serialization!(instance => &[0; size_of::()]); } #[test] fn derive_lifetime() { #[derive(Serialize)] struct MyStruct<'a> { unit: &'a u32, } let instance = MyStruct { unit: &0u32 }; assert_eq!(instance.size(), std::mem::size_of::()); assert_serialization!(instance => &[0; size_of::()]); } } #[allow(dead_code)] mod deserialize { use std::mem::size_of; use bytes::Bytes; use netherite::{assert_deserialization, Deserialize}; #[test] fn derive_empty() { #[derive(Deserialize)] struct MyStruct {} } #[test] fn derive_fields() { #[derive(Deserialize, Default, PartialEq)] struct MyStruct { field1: u32, field2: u32, unit: (), } let instance = MyStruct::default(); assert_deserialization!(&[0; size_of::()] => instance); } #[test] fn derive_generic() { #[derive(Deserialize, Default, PartialEq)] struct MyStruct { generic: T, } let instance: MyStruct = MyStruct::default(); assert_deserialization!(&[0; size_of::()] => instance); } #[test] fn derive_lifetime() { #[derive(Deserialize, Default, PartialEq)] struct MyStruct { field1: Bytes, field2: T, } let instance: MyStruct = MyStruct::default(); assert_deserialization!(&[0, 0] => instance); } }