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
//! This crate implements a plain text serializer and deserializer.  It
//! can only serialize and deserialize primitives and derivatives thereof
//! (like basic enums or newtypes).  It internally uses the `FromStr` and
//! `Display` trait to convert objects around.
//!
//! The idea of this crate is that you can use the serde system to implement
//! `FromStr` or `Display` for your own types based on the how serde would
//! handle the type.
//!
//! # From String
//!
//! To parse a value from a string the `from_str` helper can be used:
//!
//! ```rust
//! assert_eq!(serde_plain::from_str::<i32>("42").unwrap(), 42);
//! ```
//!
//! This is particularly useful if enums are in use:
//!
//! ```rust
//! # #[macro_use] extern crate serde_derive;
//! # extern crate serde_plain;
//! # fn main() {
//! #[derive(Deserialize, Debug, PartialEq, Eq)]
//! pub enum MyEnum {
//!     VariantA,
//!     VariantB,
//! }
//!
//! assert_eq!(serde_plain::from_str::<MyEnum>("VariantA").unwrap(), MyEnum::VariantA);
//! # }
//! ```
//!
//! # To String
//!
//! The inverse is also possible with `to_string`:
//!
//! ```rust
//! assert_eq!(serde_plain::to_string(&true).unwrap(), "true");
//! ```
extern crate serde;

mod macros;
mod ser;
mod de;
mod error;

pub use ser::*;
pub use de::*;
pub use error::*;