1 unstable release
Uses new Rust 2024
| 0.1.1 | May 3, 2026 |
|---|
#2647 in Encoding
50KB
1.5K
SLoC
serde_toml_ext
TOML helpers built on top of toml with configurable byte serialization and
deserialization behavior.
Overview
- default array encoding for byte fields
- hexadecimal encoding with optional
0xprefix - base64 and base64 URL-safe encoding
- shared
ConfigandBytesFormatre-exported fromserde_ext_core
Installation
[dependencies]
serde_toml_ext = "0.1.1"
serde = { version = "1", features = ["derive"] }
serde_bytes = "0.11"
Usage
use serde::Serialize;
use serde_toml_ext::{to_string, Config};
#[derive(Serialize)]
struct Example {
#[serde(with = "serde_bytes")]
data: Vec<u8>,
}
let value = Example { data: vec![1, 2, 3, 255] };
let config = Config::default().set_bytes_hex().enable_hex_prefix();
let toml = to_string(&value, &config).unwrap();
assert!(toml.contains(r#"data = "0x010203ff""#) || toml.contains(r#"data = "010203ff""#));
API
to_stringto_string_prettyfrom_strfrom_readerfrom_valueConfigBytesFormat
Notes
- Use
#[serde(with = "serde_bytes")]on byte fields that should use the custom encoding rules. - Serialization and deserialization must use the same
Configvalues.
License
MIT
Dependencies
~0.7–1.4MB
~30K SLoC