1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
// lib.rs muon crate. // // Copyright (c) 2019 Douglas Lau // #![forbid(unsafe_code)] #![deny(missing_docs)] //! # muon-rs //! //! A Rust library for the [MuON](https://github.com/muon-data/muon) data //! format, using [serde](https://serde.rs). //! //! ## Deserializing //! //! The easiest way to deserialize data is to derive [`serde::Deserialize`] on //! a struct. Then use one of the [`from_`](index.html#functions) functions. //! //! [`serde::Deserialize`]: https://docs.serde.rs/serde/trait.Deserialize.html //! //! ### 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 //! # use serde::{Deserialize, Serialize}; //! # use std::fs::File; //! #[derive(Debug, Deserialize, Serialize)] //! struct BookList { //! book: Vec<Book>, //! } //! //! #[derive(Debug, Deserialize, Serialize)] //! struct Book { //! title: String, //! author: String, //! year: Option<i16>, //! character: Vec<Character>, //! } //! //! #[derive(Debug, Deserialize, Serialize)] //! struct Character { //! name: String, //! location: Option<String>, //! } //! //! # fn main() -> Result<(), muon_rs::Error> { //! let muon = File::open("tests/books.muon")?; //! let books: BookList = muon_rs::from_reader(muon)?; //! println!("{:?}", books); //! # Ok(()) //! # } //! ``` //! //! ## Serializing //! //! Deriving [`serde::Serialize`] on a struct is just as easy. The //! [`to_`](index.html#functions) functions are used to serialize MuON data. //! //! [`serde::Serialize`]: https://docs.serde.rs/serde/trait.Serialize.html //! //! ### Example //! //! ```rust //! # use serde::Serialize; //! # use std::fs::File; //! # #[derive(Debug, Serialize)] //! # struct BookList { //! # book: Vec<Book>, //! # } //! # #[derive(Debug, Serialize)] //! # struct Book { //! # title: String, //! # author: String, //! # year: Option<i16>, //! # character: Vec<Character>, //! # } //! # #[derive(Debug, Serialize)] //! # struct Character { //! # name: String, //! # location: Option<String>, //! # } //! # fn main() -> Result<(), muon_rs::Error> { //! 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); //! # Ok(()) //! # } //! ``` //! //! ## Types //! //! MuON types can be mapped to different Rust types. //! //! <table> //! <tr> //! <th>MuON Type</th> //! <th>Rust Types</th> //! </tr> //! <tr> //! <td>text</td> //! <td><a href="https://doc.rust-lang.org/std/string/struct.String.html"> //! String</a> //! </td> //! </tr> //! <tr> //! <td>bool</td> //! <td><a href="https://doc.rust-lang.org/std/primitive.bool.html">bool</a> //! </td> //! </tr> //! <tr> //! <td>int</td> //! <td><a href="https://doc.rust-lang.org/std/primitive.i8.html">i8</a> //! <a href="https://doc.rust-lang.org/std/primitive.i16.html">i16</a> //! <a href="https://doc.rust-lang.org/std/primitive.i32.html">i32</a> //! <a href="https://doc.rust-lang.org/std/primitive.i64.html">i64</a> //! <a href="https://doc.rust-lang.org/std/primitive.i128.html">i128</a> //! <a href="https://doc.rust-lang.org/std/primitive.isize.html">isize</a> //! <a href="https://doc.rust-lang.org/std/primitive.u8.html">u8</a> //! <a href="https://doc.rust-lang.org/std/primitive.u16.html">u16</a> //! <a href="https://doc.rust-lang.org/std/primitive.u32.html">u32</a> //! <a href="https://doc.rust-lang.org/std/primitive.u64.html">u64</a> //! <a href="https://doc.rust-lang.org/std/primitive.u128.html">u128</a> //! <a href="https://doc.rust-lang.org/std/primitive.usize.html">usize</a> //! </td> //! </tr> //! <tr> //! <td>number</td> //! <td><a href="https://doc.rust-lang.org/std/primitive.f32.html">f32</a> //! <a href="https://doc.rust-lang.org/std/primitive.f64.html">f64</a> //! </td> //! </tr> //! <tr> //! <td>datetime</td> //! <td><a href="struct.DateTime.html">DateTime</a></td> //! </tr> //! <tr> //! <td>date</td> //! <td><a href="struct.Date.html">Date</a></td> //! </tr> //! <tr> //! <td>time</td> //! <td><a href="struct.Time.html">Time</a></td> //! </tr> //! <tr> //! <td>record</td> //! <td>struct implementing //! <a href="https://docs.serde.rs/serde/trait.Deserialize.html"> //! Deserialize</a> //! </td> //! </tr> //! <tr> //! <td>dictionary</td> //! <td><a href="https://doc.rust-lang.org/std/collections/struct.HashMap.html"> //! HashMap</a> //! </td> //! </tr> //! <tr> //! <td>any</td> //! <td><a href="enum.Value.html">Value</a></td> //! </tr> //! </table> //! mod common; mod datetime; mod de; mod error; mod lines; mod parse; mod schema; mod ser; pub use datetime::{Date, DateTime, Time, TimeOffset}; pub use de::{from_reader, from_slice, from_str, Deserializer}; pub use error::{Error, Result}; pub use schema::Value; pub use ser::{to_string, to_vec, to_writer, Serializer};