Crate toon_core

Crate toon_core 

Source
Expand description

TOON-LD Core Library

High-performance serializer/parser for TOON-LD (Token-Oriented Object Notation for Linked Data). Implements the TOON format v3.0 specification with JSON-LD context expansion support.

§Overview

TOON-LD is a text serialization format designed to minimize token count while preserving the semantic richness of JSON-LD. It achieves 40-60% token reduction compared to equivalent JSON-LD representations.

§Features

  • Tabular Arrays: Arrays of objects are serialized as CSV-like tables with a header
  • Primitive Arrays: Simple value arrays use compact inline notation
  • JSON-LD Context: Full support for URI compaction/expansion via @context
  • JSON-LD 1.1 Keywords: Support for all standard JSON-LD keywords

§Example

use toon_core::{encode, decode};

let json_ld = r#"{
    "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
    "http://xmlns.com/foaf/0.1/name": "Alice",
    "http://xmlns.com/foaf/0.1/age": 30
}"#;

// Convert JSON-LD to TOON-LD
let toon = encode(json_ld).unwrap();
assert!(toon.contains("foaf:name: Alice"));

// Convert back to JSON-LD
let back = decode(&toon).unwrap();

§Modules

  • context: JSON-LD context handling for URI compaction/expansion
  • error: Error types for TOON-LD operations
  • keywords: JSON-LD keyword constants and utilities
  • parser: TOON-LD parser implementation
  • serializer: TOON-LD serializer implementation

Re-exports§

pub use context::JsonLdContext;
pub use error::Result;
pub use error::ToonError;
pub use parser::ToonParser;
pub use serializer::ToonSerializer;
pub use keywords::*;

Modules§

context
JSON-LD Context handling for TOON-LD.
error
Error types for TOON-LD operations.
keywords
JSON-LD keyword constants for TOON-LD.
parser
TOON-LD Parser
serializer
TOON-LD Serializer

Functions§

decode
Decode TOON-LD string to JSON-LD format
encode
Encode JSON-LD string to TOON-LD format