Skip to main content

from_decoder

Function from_decoder 

Source
pub fn from_decoder<'de, T: Deserialize<'de>>(
    decoder: &mut Decoder<'de>,
) -> Result<T>
Available on crate feature serde only.
Expand description

Decode the next serde value from an in-memory Decoder, leaving the cursor after it. Borrowed fields point into the decoder’s input.

§Errors

As for from_slice, except that trailing input is not an error.

§Examples

use pack_io::{Decoder, Encoder};

let mut enc = Encoder::new();
enc.write(&1_u8).unwrap();
enc.write(&"two").unwrap();
let bytes = enc.into_inner();

let mut dec = Decoder::new(&bytes);
let a: u8 = pack_io::serde::from_decoder(&mut dec).unwrap();
let b: &str = pack_io::serde::from_decoder(&mut dec).unwrap();
assert_eq!((a, b), (1, "two"));