serde_plain/lib.rs
1//! This crate implements a plain text serializer and deserializer. It
2//! can only serialize and deserialize primitives and derivatives thereof
3//! (like basic enums or newtypes). It internally uses the
4//! [`FromStr`](std::str::FromStr) and [`Display`](std::fmt::Display) trait to
5//! convert objects around.
6//!
7//! The idea of this crate is that you can use the serde system to implement
8//! [`FromStr`](std::str::FromStr) or [`Display`](std::fmt::Display) for your own
9//! types based on the how serde would handle the type.
10//!
11//! # From String
12//!
13//! To parse a value from a string the [`from_str`] helper can be used:
14//!
15//! ```rust
16//! assert_eq!(serde_plain::from_str::<i32>("42").unwrap(), 42);
17//! ```
18//!
19//! This is particularly useful if enums are in use:
20//!
21//! ```rust
22//! # #[macro_use] extern crate serde_derive;
23//! use serde::Deserialize;
24//!
25//! # fn main() {
26//! #[derive(Deserialize, Debug, PartialEq, Eq)]
27//! pub enum MyEnum {
28//! VariantA,
29//! VariantB,
30//! }
31//!
32//! assert_eq!(serde_plain::from_str::<MyEnum>("VariantA").unwrap(), MyEnum::VariantA);
33//! # }
34//! ```
35//!
36//! # To String
37//!
38//! The inverse is also possible with [`to_string`]:
39//!
40//! ```rust
41//! assert_eq!(serde_plain::to_string(&true).unwrap(), "true");
42//! ```
43mod de;
44mod error;
45mod macros;
46mod ser;
47
48pub use crate::de::*;
49pub use crate::error::*;
50pub use crate::ser::*;