Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore the length Serde provides
Serde supplies the expected length of a tuple when deserializing. Prior to this change it was ensured that this length also matches the length of the CBOR encoded list. Removing this check enables using `#[serde(default)]` when the data is encoded as a tuple. Example: use serde_tuple::{Deserialize_tuple, Serialize_tuple}; #[derive(Debug, Serialize_tuple, Deserialize_tuple)] struct Tree { height: u8, #[serde(default)] age: u8, } fn main() { // [3, 20] let tree1_cbor = b"\x82\x02\x14"; let tree1: Tree = serde_ipld_dagcbor::from_slice(tree1_cbor).unwrap(); println!("tree1: {:?}", tree1); // [5] let tree2_cbor = b"\x81\x05"; let tree2: Tree = serde_ipld_dagcbor::from_slice(tree2_cbor).unwrap(); println!("tree2: {:?}", tree2); }
- Loading branch information