use bincode; use bincode::{config, Decode, Encode}; pub struct Bincode; impl native_model::Encode for Bincode { type Error = bincode::error::EncodeError; fn encode(obj: &T) -> Result, bincode::error::EncodeError> { bincode::encode_to_vec(obj, config::standard()) } } impl native_model::Decode for Bincode { type Error = bincode::error::DecodeError; fn decode(data: Vec) -> Result { bincode::decode_from_slice(&data, config::standard()).map(|(result, _)| result) } } use native_model_macro::native_model; #[derive(Encode, Decode, PartialEq, Debug)] #[native_model(id = 1, version = 1, with = Bincode)] struct DotV1(u32, u32); #[test] fn test_bincode_encode_decode() { // Application 1 let dot = DotV1(1, 2); let bytes = native_model::encode(&dot).unwrap(); // Application 1 let (dot, _) = native_model::decode::(bytes).unwrap(); assert_eq!(dot, DotV1(1, 2)); }