Thanks to visit codestin.com
Credit goes to github.com

Skip to content

hxphsts/serde_toon

Repository files navigation

serde_toon

A Serde-compatible TOON serialization library for Rust.

Crates.io Documentation License

What is TOON?

TOON (Token-Oriented Object Notation) is a compact serialization format optimized for LLMs, using 30-60% fewer tokens than JSON.

Example - Same data, different sizes:

// JSON: 171 characters
[
  {
    "id": 1,
    "name": "Alice",
    "email": "[email protected]",
    "active": true
  },
  {
    "id": 2,
    "name": "Bob",
    "email": "[email protected]",
    "active": true
  }
]

// TOON: 86 characters (50% reduction)
[2]{active,email,id,name}:
  true,alice@example.com,1,Alice
  true,bob@example.com,2,Bob

See examples/token_efficiency.rs.

Quick Start

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_toon = "0.2"
use serde::{Deserialize, Serialize};
use serde_toon::{to_string, from_str};

#[derive(Serialize, Deserialize)]
struct User {
    id: u32,
    name: String,
}

let user = User { id: 123, name: "Alice".into() };
let toon = to_string(&user)?; // Serialize to TOON
let back: User = from_str(&toon)?; // Deserialize from TOON

Dynamic Values

use serde_toon::{toon, to_string};

let data = toon!({
    "users": [
        {"id": 1, "name": "Alice"},
        {"id": 2, "name": "Bob"}
    ],
    "active": true
}); // toon! macro -> serde_toon::Value

let serialized = to_string(&data)?;

See examples/dynamic_values.rs, examples/macro.rs.

Features

  • Full Serde integration
  • Zero-copy deserialization
  • Configurable output
  • Rich error messages
  • No unsafe code

Documentation

See https://docs.rs/serde_toon

License

MIT OR Apache-2.0

About

A Serde-compatible TOON serialization library for Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages