asun
Rust support for ASUN, a schema-driven format for compact structured data with serde-based encoding and decoding.
Why ASUN?
json
Standard JSON repeats every field name in every record. When you send structured data to an LLM, over an API, or across services, that repetition wastes tokens, bytes, and attention:
asun
ASUN declares the schema once and streams data as compact tuples:
[{id, name, active}]:
(1,Alice,true),
(2,Bob,false),
(3,Carol,true)
Fewer tokens. Smaller payloads. Clearer structure, and faster parsing than repeated-object JSON.
Highlights
- Serde-based text encoding and decoding
- Current API uses
encode/decode, not the olderto_string/from_strnames - Optional scalar-hint schema output
- Pretty text output and binary format
- Works well for structs, vectors, options, enums, nested data, and entry-list based keyed collections
Install
[]
= "*"
= { = "1", = ["derive"] }
Quick Start
use ;
use ;
Encode a vector
let users = vec!;
let text = encode?;
let typed = encode_typed?;
let decoded: = decode?;
Pretty and binary output
use ;
let pretty = encode_pretty?;
let pretty_typed = encode_pretty_typed?;
let bin = encode_binary?;
let decoded: = decode_binary?;
Current API
| Function | Purpose |
|---|---|
encode / encode_typed |
Encode to text |
decode |
Decode from text |
encode_pretty / encode_pretty_typed |
Pretty text output |
encode_binary |
Encode to binary |
decode_binary |
Decode from binary |
Run Examples
Contributors
Benchmark Snapshot
Run the benchmark example with:
The Rust benchmark now uses the same two-line summary style as the Go example:
Flat struct × 1000 (8 fields, vec)
Serialize: JSON 411.05ms / 121675 B | ASUN 175.25ms (2.3x) / 56718 B (46.6%) | BIN 41.32ms (9.9x) / 74454 B (61.2%)
Deserialize: JSON 287.06ms | ASUN 195.57ms (1.5x) | BIN 64.62ms (4.4x)
ASUN / BIN ratios are measured against JSON, and size percentages show the remaining size relative to JSON.
License
MIT