toon_rust/
lib.rs

1//! Token-Oriented Object Notation (TOON) - Rust implementation
2//!
3//! TOON is a compact, human-readable format designed to reduce token usage
4//! in Large Language Model (LLM) prompts by 30–60% compared to JSON.
5//!
6//! # Examples
7//!
8//! ## Standalone API
9//!
10//! ```rust
11//! use toon_rust::{encode, decode};
12//! use serde_json::json;
13//!
14//! let data = json!({
15//!     "items": [
16//!         {"sku": "A1", "qty": 2, "price": 9.99},
17//!         {"sku": "B2", "qty": 1, "price": 14.5}
18//!     ]
19//! });
20//!
21//! let toon = encode(&data, None).unwrap();
22//! let decoded = decode(&toon, None).unwrap();
23//! ```
24//!
25//! ## Serde API (requires `serde` feature)
26//!
27//! ```rust,no_run
28//! use serde::{Serialize, Deserialize};
29//! use toon_rust::{to_string, from_str};
30//!
31//! #[derive(Serialize, Deserialize)]
32//! struct Product {
33//!     sku: String,
34//!     qty: u32,
35//!     price: f64,
36//! }
37//!
38//! let products = vec![
39//!     Product { sku: "A1".to_string(), qty: 2, price: 9.99 },
40//!     Product { sku: "B2".to_string(), qty: 1, price: 14.5 },
41//! ];
42//!
43//! let toon = to_string(&products).unwrap();
44//! let decoded: Vec<Product> = from_str(&toon).unwrap();
45//! ```
46
47pub mod decode;
48pub mod encode;
49pub mod error;
50pub mod options;
51mod simd;
52
53pub use decode::decode;
54pub use encode::encode;
55pub use error::Error;
56pub use options::{DecodeOptions, EncodeOptions};
57
58#[cfg(feature = "serde")]
59pub mod serde_api;
60
61#[cfg(feature = "serde")]
62pub use serde_api::{from_reader, from_str, to_string, to_writer};