use std::convert::{TryFrom, TryInto}; use deku::prelude::*; #[test] fn test_generic_struct() { #[derive(PartialEq, Debug, DekuRead, DekuWrite)] struct TestStruct where T: deku::DekuWriter + for<'a> deku::DekuReader<'a>, { field_a: T, } let test_data: Vec = [0x01].to_vec(); let ret_read = TestStruct::::try_from(test_data.as_slice()).unwrap(); assert_eq!(TestStruct:: { field_a: 0x01 }, ret_read); let ret_write: Vec = ret_read.try_into().unwrap(); assert_eq!(test_data, ret_write); } #[test] fn test_generic_enum() { #[derive(PartialEq, Debug, DekuRead, DekuWrite)] #[deku(id_type = "u8")] enum TestEnum where T: deku::DekuWriter + for<'a> deku::DekuReader<'a>, { #[deku(id = "1")] VariantT(T), } let test_data: Vec = [0x01, 0x02].to_vec(); let ret_read = TestEnum::::try_from(test_data.as_slice()).unwrap(); assert_eq!(TestEnum::::VariantT(0x02), ret_read); let ret_write: Vec = ret_read.try_into().unwrap(); assert_eq!(test_data, ret_write); }