Crate serde_txtrecord

Source
Expand description

§Serde TXT Record

A serialization and deserialization library for TXT records.

This library provides custom serde support for converting Rust data structures to and from TXT record format with the following patterns:

  • Simple key-value pairs: key: valuekey=value
  • Arrays: key: ["val", "bal"]key_0=val, key_1=bal, key_len=2
  • Objects: key: { foo: "val", bar: "bal" }key.foo=val, key.bar=bal
  • Record length limits: Each key=value record can be limited to a maximum length (default: 255 characters)
  • Configurable separators and suffixes: Customize array separators, object separators, and array length suffixes

§Example

use serde::{Serialize, Deserialize};
use serde_txtrecord::{to_txt_records, from_txt_records};

#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Person {
    name: String,
    age: u32,
}

let person = Person {
    name: "Alice".to_string(),
    age: 30,
};

// serialize to TXT records (key-value pairs of strings)
let records = to_txt_records(&person).unwrap();

// deserialize back from TXT records
let deserialized: Person = from_txt_records(records).unwrap();
assert_eq!(person, deserialized);

Re-exports§

pub use config::TxtRecordConfig;
pub use de::from_txt_records;
pub use de::from_txt_records_with_config;
pub use de::DeserializeError;
pub use de::TxtRecordDeserializer;
pub use ser::to_txt_records;
pub use ser::to_txt_records_with_config;
pub use ser::TxtRecordError;
pub use ser::TxtRecordSerializer;

Modules§

config
de
ser