zerotier-one/vendor/serde_plain
2026-02-19 20:24:30 +03:00
..
src created vendored crates 2026-02-19 20:24:30 +03:00
tests created vendored crates 2026-02-19 20:24:30 +03:00
.cargo-checksum.json created vendored crates 2026-02-19 20:24:30 +03:00
.cargo_vcs_info.json created vendored crates 2026-02-19 20:24:30 +03:00
Cargo.toml created vendored crates 2026-02-19 20:24:30 +03:00
Cargo.toml.orig created vendored crates 2026-02-19 20:24:30 +03:00
CHANGELOG created vendored crates 2026-02-19 20:24:30 +03:00
LICENSE-APACHE created vendored crates 2026-02-19 20:24:30 +03:00
LICENSE-MIT created vendored crates 2026-02-19 20:24:30 +03:00
README.md created vendored crates 2026-02-19 20:24:30 +03:00

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