IPLD to Rust type

Hi,

I’m trying to decode the data field of IPNS records, these are dag-cbor.

let document: libipld::Ipld = serde_ipld_dagcbor::from_slice(&record.data).unwrap();

Result in

{"Sequence": 5, "TTL": 0, "Validity": [50, 48, 50, 51, 45, 48, 53, 45, 48, 50, 84, 49, 51, 58, 52, 51, 58, 52, 49, 46, 50, 54, 50, 49, 51, 54, 55, 50, 55, 90], "ValidityType": 0, "Value": [47, 105, 112, 102, 115, 47, 98, 97, 102, 121, 114, 101, 105, 100, 51, 108, 106, 112, 116, 106, 114, 109, 114, 121, 120, 100, 101, 108, 55, 55, 116, 116, 103, 98, 102, 53, 114, 110, 118, 121, 52, 105, 112, 107, 98, 98, 120, 51, 117, 53, 50, 116, 51, 119, 108, 115, 102, 110, 102, 52, 121, 102, 121, 51, 105]}

but then I try to use a rust type like this.

#[derive(Serialize, Deserialize, DagCbor, Clone, Debug, PartialEq, Eq)]
struct DagCborDocument {
    #[ipld(rename = "Sequence")]
    #[serde(rename = "Sequence")]
    sequence: u64,

    #[ipld(rename = "TTL")]
    #[serde(rename = "TTL")]
    ttl: u64,

    #[ipld(rename = "Validity")]
    #[serde(rename = "Validity")]
    validity: Vec<u8>,

    #[ipld(rename = "ValidityType")]
    #[serde(rename = "ValidityType")]
    validity_type: i32,

    #[ipld(rename = "Value")]
    #[serde(rename = "Value")]
    value: Vec<u8>,
}

and no matter what I try it errors.

let document: DagCborDocument = DagCborCodec.decode(&record.data).unwrap();
//Result -> Unexpected cbor code `0x58` when decoding `alloc::vec::Vec<u8>`.

let document: DagCborDocument = serde_ipld_dagcbor::from_slice(&record.data).unwrap();
//Result -> Mismatch { expect_major: 4, byte: 88 }

I also don’t know which crate to use serde_ipld_dagcbor or libipld

How can I get from and to a rust type?