use lurk_ipld::cbor::DagCborCodec; use lurk_ipld::codec::{Decode, Encode}; use lurk_ipld::ipld::Ipld; use lurk_ipld::{ipld, DagCbor}; use std::io::Cursor; #[derive(Clone, Debug, Default, PartialEq, DagCbor)] struct RenameFields { #[ipld(rename = "hashAlg")] hash_alg: String, } fn main() -> Result<(), Box> { let data = RenameFields { hash_alg: "murmur3".to_string(), }; let mut bytes = Vec::new(); data.encode(DagCborCodec, &mut bytes)?; let ipld: Ipld = Decode::decode(DagCborCodec, &mut Cursor::new(bytes.as_slice()))?; let expect = ipld!({ "hashAlg": "murmur3", }); assert_eq!(ipld, expect); let data2 = RenameFields::decode(DagCborCodec, &mut Cursor::new(bytes.as_slice()))?; assert_eq!(data, data2); Ok(()) }