ron_reboot/utf8_parser/serde/
mod.rs1use std::{fs::File, io::Read, path::Path};
2
3use serde::de::DeserializeOwned;
4
5pub use self::de::from_str;
6use crate::Error;
7
8mod de;
9#[cfg(test)]
10mod tests;
11
12pub fn from_reader<R: Read, T: DeserializeOwned>(mut reader: R) -> Result<T, Error> {
13 let mut buf = String::new();
14
15 reader.read_to_string(&mut buf).map_err(Error::from)?;
16
17 from_str(&buf)
18}
19
20pub fn from_file<T: DeserializeOwned>(path: impl AsRef<Path>) -> Result<T, Error> {
21 let path = path.as_ref();
22
23 File::open(path)
24 .map_err(Error::from)
25 .and_then(from_reader)
26 .map_err(|e| e.context_file_name(path.display().to_string()))
27}