Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mitsuhiko/serde-plain
A serde serializer that serializes a subset of types into plain strings
https://github.com/mitsuhiko/serde-plain
Last synced: 4 days ago
JSON representation
A serde serializer that serializes a subset of types into plain strings
- Host: GitHub
- URL: https://github.com/mitsuhiko/serde-plain
- Owner: mitsuhiko
- License: apache-2.0
- Created: 2018-03-12T14:05:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-31T20:29:11.000Z (about 1 year ago)
- Last Synced: 2024-12-23T08:07:46.262Z (11 days ago)
- Language: Rust
- Size: 31.3 KB
- Stars: 55
- Watchers: 3
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE-APACHE
Awesome Lists containing this project
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:
```rust
assert_eq!(serde_plain::from_str::("42").unwrap(), 42);
```This is particularly useful if enums are in use:
```rust
use serde::Deserialize;#[derive(Deserialize, Debug, PartialEq, Eq)]
pub enum MyEnum {
VariantA,
VariantB,
}assert_eq!(serde_plain::from_str::("VariantA").unwrap(), MyEnum::VariantA);
```## To String
The inverse is also possible with to_string:
```rust
assert_eq!(serde_plain::to_string(&true).unwrap(), "true");
```