# IPLD to Rust type

**URL:** <https://discuss.ipfs.tech/t/ipld-to-rust-type/15582>\
**Category:** rust-ipfs\
**Tags:** ipld\
**Created:** [November 28, 2022, 4:41pm UTC](https://discuss.ipfs.tech/t/ipld-to-rust-type/15582 "2022-11-28T16:41:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SionoiS](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/sionois/32/5103_2.png) [@SionoiS](https://discuss.ipfs.tech/u/SionoiS)\
**Post date:** [November 28, 2022, 4:41pm UTC](https://discuss.ipfs.tech/t/ipld-to-rust-type/15582/1 "2022-11-28T16:41:21Z")

</div>

Hi,

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

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

```

Result in

```auto
{"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.

```auto
#[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.

```auto
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?
