Skip to main content

from_reader

Function from_reader 

Source
pub fn from_reader<R: Read, T: DeserializeOwned>(reader: R) -> Result<T, Error>
Expand description

Deserialize one UTF-8 YAML document from an I/O reader under the default limits.

Reads at most Limits::default().max_input_bytes + 1 bytes from reader before failing with ErrorKind::Limit (LimitKind::InputBytes), preventing unbounded reads from hostile or infinite streams.

#[derive(serde::Deserialize)]
struct Config {
    name: String,
}

let config: Config = ayaml::from_reader("name: ayaml\n".as_bytes()).unwrap();
assert_eq!(config.name, "ayaml");

Trailing documents are rejected.

ยงErrors

Returns ErrorKind::Io when reading from reader fails, ErrorKind::Limit when a configured limit is exceeded, ErrorKind::InvalidEncoding when the input is not valid UTF-8, or a parse/Serde error when the document or target is invalid.