## muon-rs A Rust library for the [MuON](https://github.com/muon-data/muon) data format, using [serde](https://serde.rs). See [documentation](https://docs.rs/muon-rs) for more information. ## Deserializing The easiest way to deserialize data is to derive [`serde::Deserialize`] on a struct. Then use one of the [`from_`] functions. [`serde::Deserialize`]: https://docs.serde.rs/serde/trait.Deserialize.html [`from_`]: https://docs.rs/muon-rs/latest/muon_rs/index.html#functions ### Example MuON file: ```muon book: Pale Fire author: Vladimir Nabokov year: 1962 character: John Shade location: New Wye character: Charles Kinbote location: Zembla book: The Curious Incident of the Dog in the Night-Time author: Mark Haddon year: 2003 character: Christopher Boone location: Swindon character: Siobhan ``` Rust code: ```rust #[derive(Debug, Deserialize, Serialize)] struct BookList { book: Vec, } #[derive(Debug, Deserialize, Serialize)] struct Book { title: String, author: String, year: Option, character: Vec, } #[derive(Debug, Deserialize, Serialize)] struct Character { name: String, location: Option, } let muon = File::open("tests/books.muon")?; let books: BookList = muon_rs::from_reader(muon)?; println!("{:?}", books); ``` ## Serializing Deriving [`serde::Serialize`] on a struct is just as easy. The [`to_`] functions are used to serialize MuON data. [`serde::Serialize`]: https://docs.serde.rs/serde/trait.Serialize.html [`to_`]: https://docs.rs/muon-rs/latest/muon_rs/index.html#functions ### Example ```rust let books = BookList { book: vec![ Book { title: "Flight".to_string(), author: "Sherman Alexie".to_string(), year: Some(2007), character: vec![ Character { name: "Zits".to_string(), location: Some("Seattle".to_string()), }, Character { name: "Justice".to_string(), location: None, }, ], }, ], }; let muon = muon_rs::to_string(&books)?; println!("{:?}", muon); ``` ## Types MuON types can be mapped to different Rust types.
MuON Type Rust Types
text String
bool bool
int i8i16i32i64i128isizeu8u16u32u64u128usize
number f32f64
datetime DateTime
date Date
time Time
record struct implementing Deserialize
dictionary HashMap
any Value
### Contributing Any feedback, bug reports or enhancement requests are welcome! Please create an [issue](https://github.com/muon-data/muon-rs/issues) and join the fun.