Skip to main content

from_reader_strict

Function from_reader_strict 

Source
pub fn from_reader_strict<R, T>(reader: R) -> Result<T>
where R: Read, T: for<'de> Deserialize<'de> + 'static,
Available on crate features std and strict-deserialise only.
Expand description

Strict deserialise from an IO reader — like from_reader but errors if the input contains keys the target type T does not declare.

Same semantics as from_str_strict. Reads the entire stream into memory before parsing, mirroring from_reader.

§Errors

  • The reader returns an I/O error or the data is not valid UTF-8.
  • Any key in the YAML document is not declared on T.
  • Any of the regular from_reader error paths.

§Examples

use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Config {
    port: u16,
}

let yaml = b"port: 8080\nporrt: 9090\n".to_vec();
assert!(noyalib::from_reader::<_, Config>(&yaml[..]).is_ok());
assert!(noyalib::from_reader_strict::<_, Config>(&yaml[..]).is_err());