serde_plain

Crates.ioserde_plain
lib.rsserde_plain
version1.0.2
sourcesrc
created_at2018-03-12 22:31:10.313711
updated_at2023-08-25 14:51:19.466002
descriptionA restricted plain text serializer for serde
homepagehttps://docs.rs/serde_plain
repositoryhttps://github.com/mitsuhiko/serde-plain
max_upload_size
id55238
size42,896
Armin Ronacher (mitsuhiko)

documentation

https://docs.rs/serde_plain

README

Serde Plain

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.

From String

To parse a value from a string the from_str helper can be used:

assert_eq!(serde_plain::from_str::<i32>("42").unwrap(), 42);

This is particularly useful if enums are in use:

use serde::Deserialize;

#[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:

assert_eq!(serde_plain::to_string(&true).unwrap(), "true");
Commit count: 27

cargo fmt