| Crates.io | serde-extras |
| lib.rs | serde-extras |
| version | 0.1.1 |
| created_at | 2025-06-29 18:08:22.736762+00 |
| updated_at | 2025-06-29 18:33:05.124225+00 |
| description | A lightweight crate providing utilities for serializing and deserializing types using their string representations with Serde. |
| homepage | https://github.com/cygnus9/serde-extras |
| repository | https://github.com/cygnus9/serde-extras |
| max_upload_size | |
| id | 1730998 |
| size | 24,541 |
A lightweight crate providing utilities for serializing and deserializing types using their string representations with Serde.
ToString and FromStr via Serde attributes.Add to your Cargo.toml:
serde-extras = "0.1"
Annotate your struct fields with Serde's with attribute:
use std::net::IpAddr;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Wrapper {
#[serde(with = "serde_extras::to_from_str")]
ip: IpAddr,
}
This will serialize the ip field as a string and deserialize it from a string.
use std::net::IpAddr;
use serde::{Serialize, Deserialize};
use serde_json;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Wrapper {
#[serde(with = "serde_extras::to_from_str")]
ip: IpAddr,
}
let w = Wrapper { ip: IpAddr::V4("127.0.0.1".parse().unwrap()) };
let json = serde_json::to_string(&w).unwrap();
assert_eq!(json, r#"{"ip":"127.0.0.1"}"#);
let de: Wrapper = serde_json::from_str(&json).unwrap();
assert_eq!(de, w);
This crate is a lightweight alternative to a small portion of serde_with. If you only need simple string-based (de)serialization helpers, serde-extras may be a better fit. For more advanced features, consider using serde_with.
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in serde-extras by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.