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

#66 in Encoding

Download history 87048/week @ 2024-07-21 84776/week @ 2024-07-28 87850/week @ 2024-08-04 82349/week @ 2024-08-11 91426/week @ 2024-08-18 94188/week @ 2024-08-25 101645/week @ 2024-09-01 102003/week @ 2024-09-08 90108/week @ 2024-09-15 104551/week @ 2024-09-22 95768/week @ 2024-09-29 93430/week @ 2024-10-06 99959/week @ 2024-10-13 113077/week @ 2024-10-20 105563/week @ 2024-10-27 110542/week @ 2024-11-03

434,523 downloads per month
Used in 235 crates (61 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

~105–340KB