6 releases (3 stable)

1.0.2 Aug 25, 2023
1.0.1 Oct 22, 2022
1.0.0 Aug 29, 2021
0.3.0 Mar 19, 2018
0.1.0 Mar 12, 2018

#57 in Encoding

Download history 63834/week @ 2023-12-14 39364/week @ 2023-12-21 41539/week @ 2023-12-28 70037/week @ 2024-01-04 65642/week @ 2024-01-11 74299/week @ 2024-01-18 70552/week @ 2024-01-25 76655/week @ 2024-02-01 66436/week @ 2024-02-08 67611/week @ 2024-02-15 71730/week @ 2024-02-22 78325/week @ 2024-02-29 80623/week @ 2024-03-07 77641/week @ 2024-03-14 74391/week @ 2024-03-21 57637/week @ 2024-03-28

305,267 downloads per month
Used in 213 crates (55 directly)

MIT/Apache

25KB
492 lines

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");

lib.rs:

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:

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");

Dependencies

~110–350KB