[−][src]Function muon_rs::from_reader
pub fn from_reader<R, T>(reader: R) -> Result<T> where
R: Read,
T: DeserializeOwned,
Deserialize T
from a reader IO stream containing MuON
This may call many short reads, so wrapping the reader with
std::io::BufReader
.
Example
#[derive(Debug, Deserialize)] struct BookList { book: Vec<Book>, } #[derive(Debug, Deserialize)] struct Book { title: String, author: String, year: Option<i16>, character: Vec<Character>, } #[derive(Debug, Deserialize)] struct Character { name: String, location: Option<String>, } let muon = File::open("tests/books.muon")?; let books: BookList = muon_rs::from_reader(muon)?; println!("{:?}", books);
Errors
An error will be returned if the conversion cannot be performed. This can occur for a number of reasons:
- An IO error is encountered from reader
- The MuON data is malformed
- The structure of the MuON data does not match the structure of
T
- A required field is missing
- A value is too big to fit within a primitive defined by
T