Crates.io | serde_plain2 |
lib.rs | serde_plain2 |
version | 0.1.0 |
source | src |
created_at | 2024-12-05 00:25:00.107066 |
updated_at | 2024-12-05 00:25:00.107066 |
description | Fork of serde_plain. A restricted plain text serializer for serde |
homepage | https://docs.rs/serde_plain2 |
repository | https://github.com/0xJWLabs/serde-plain2 |
max_upload_size | |
id | 1472696 |
size | 32,731 |
This is a personal fork of 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.
To parse a value from a string the from_str helper can be used:
assert_eq!(serde_plain2::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_plain2::from_str::<MyEnum>("VariantA").unwrap(), MyEnum::VariantA);
The inverse is also possible with to_string:
assert_eq!(serde_plain2::to_string(&true).unwrap(), "true");