Rust Guide
Rust is the most mature ASUN implementation in the repository and the best reference for the full API surface.
Minimum Version
- Rust
1.85+ serdewithderive
Implementation Model
- Generic codecs are built on top of
serde::Serializeandserde::Deserialize. - Text and binary decode both use the target type
T. - Pretty and typed text output are first-class APIs.
Current Support
encode,encode_typedencode_pretty,encode_pretty_typeddecodeencode_binary,decode_binary- Structs, enums, vectors, options, nested data, entry-list keyed collections
Example
rust
use asun::{decode, encode_typed, Result};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct User {
id: i64,
name: String,
active: bool,
}
fn main() -> Result<()> {
let text = encode_typed(&User {
id: 1,
name: "Alice".into(),
active: true,
})?;
let restored: User = decode(&text)?;
assert_eq!(restored.id, 1);
Ok(())
}Notes
- Rust uses host types such as
i64andf64, but the ASUN schema still only exposesint,float,bool, andstr. - Binary decode requires the target type, not a schema string.
- Keyed collections should be explicit entry structs.
Build and Test
bash
cd asun-rs
cargo test
cargo run --release --example basic
cargo run --release --example complex
cargo run --release --example bench