[−][src]Function cborg::decode_to
pub fn decode_to<'a, T, I>(stream: I) -> Result<Option<T>> where
T: FromValue,
I: IntoIterator<Item = &'a u8>,
Decode a given IntoIterator into a given object.
Examples
Basic usage:
use std::collections::HashMap; let bytes = &[0b1010_0010, 0b0011_1000, 0b0001_1000, 0b0110_0011, 0x61, 0x62, 0x63, 0b0000_0111, 0b0110_0011, 0x44, 0x45, 0x46]; let map: HashMap<i8, String> = cborg::decode_to(bytes).unwrap().unwrap(); assert_eq!("abc", map[&-25]); assert_eq!("DEF", map[&7]);
let bytes = &[0b1000_0011, 11, 22, 0b0001_1000, 33]; let array: Vec<u32> = cborg::decode_to(bytes).unwrap().unwrap(); assert_eq!(11, array[0]); assert_eq!(22, array[1]); assert_eq!(33, array[2]);