toon_ld/
lib.rs

1//! # TOON-LD
2//!
3//! **Token-Oriented Object Notation for Linked Data** — A compact RDF serialization format
4//! that achieves 40-60% token reduction compared to JSON-LD.
5//!
6//! This crate provides high-level conversion functions between JSON-LD and TOON-LD formats.
7//! TOON-LD extends TOON in the same way that JSON-LD extends JSON: every valid TOON-LD
8//! document is also a valid TOON document.
9//!
10//! ## Quick Start
11//!
12//! ```rust
13//! use toon_ld::{encode, decode};
14//!
15//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
16//! // Convert JSON-LD to TOON-LD
17//! let json_ld = r#"{
18//!     "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
19//!     "foaf:name": "Alice"
20//! }"#;
21//!
22//! let toon = encode(json_ld)?;
23//! println!("TOON-LD:\n{}", toon);
24//!
25//! // Convert back to JSON-LD
26//! let back_to_json = decode(&toon)?;
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! ## Tabular Arrays
32//!
33//! TOON-LD's key feature is efficient serialization of arrays of objects:
34//!
35//! ```rust
36//! use toon_ld::encode;
37//!
38//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
39//! let json_ld = r#"{
40//!     "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
41//!     "@graph": [
42//!         {"@id": "ex:1", "foaf:name": "Alice", "foaf:age": 30},
43//!         {"@id": "ex:2", "foaf:name": "Bob", "foaf:age": 25}
44//!     ]
45//! }"#;
46//!
47//! let toon = encode(json_ld)?;
48//! // Output uses tabular format with shared headers:
49//! // @graph[2]{@id,foaf:age,foaf:name}:
50//! //   ex:1, 30, Alice
51//! //   ex:2, 25, Bob
52//! # Ok(())
53//! # }
54//! ```
55//!
56//! ## Features
57//!
58//! - **40-60% token reduction** compared to JSON-LD
59//! - **Full JSON-LD compatibility** with round-trip conversion
60//! - **Tabular arrays** for efficient serialization of uniform data
61//! - **Context support** for URI compaction
62//! - **Value nodes** with language tags and datatypes
63//! - **Optimized parsing** with automatic tabular array detection
64
65// Re-export everything from toon-core
66pub use toon_core::*;
67
68// Re-export commonly used types from dependencies
69pub use serde_json::Value;