Function forest_filecoin::utils::encoding::fallback_de_ipld_dagcbor::from_slice
source · pub fn from_slice<'a, T>(buf: &'a [u8]) -> Result<T, DecodeError<Infallible>>where
T: Deserialize<'a>,
Expand description
Decodes a value from CBOR data in a slice.
§Examples
De-serialize a String
let v: Vec<u8> = vec![0x66, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72];
let value: String = de::from_slice(&v[..]).unwrap();
assert_eq!(value, "foobar");
De-serialize a borrowed string with zero copies.
let v: Vec<u8> = vec![0x66, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72];
let value: &str = de::from_slice(&v[..]).unwrap();
assert_eq!(value, "foobar");