toon_format_rs/lib.rs
1//! # TOON Format - Token-Oriented Object Notation
2//!
3//! A Rust implementation of the TOON (Token-Oriented Object Notation) format.
4//! TOON is a compact, human-readable serialization format designed to minimize
5//! tokens when sending structured data to Large Language Models (LLMs).
6//!
7//! ## Quick Start
8//!
9//! ```rust
10//! use toon_format_rs::{parse, to_string, Value};
11//!
12//! // Parse TOON string
13//! let input = r#"id: 123
14//! name: Alice
15//! active: true"#;
16//!
17//! let value = parse(input).unwrap();
18//! assert_eq!(value.get("id").unwrap().as_i64(), Some(123));
19//!
20//! // Serialize to TOON
21//! let output = to_string(&value).unwrap();
22//! assert!(output.contains("id: 123"));
23//! ```
24//!
25//! ## Features
26//!
27//! - **Compact**: 30-60% fewer tokens than JSON for uniform arrays
28//! - **Human-readable**: YAML-like indentation with CSV-like tabular arrays
29//! - **Schema-aware**: Explicit array lengths and field lists
30//! - **Lossless**: Convert JSON → TOON → JSON without data loss
31//! - **LLM-optimized**: Designed specifically for LLM prompts
32
33pub mod error;
34pub mod lexer;
35pub mod parser;
36pub mod serializer;
37pub mod value;
38
39// Re-export main types
40pub use error::{Error, Result};
41pub use lexer::{Lexer, Token};
42pub use parser::{parse, Parser};
43pub use serializer::{to_string, to_string_pretty, Delimiter, SerializeOptions, Serializer};
44pub use value::Value;
45
46#[cfg(feature = "json")]
47mod json_convert;
48
49#[cfg(feature = "json")]
50pub use json_convert::{json_to_toon, toon_to_json, toon_to_json_pretty};