Examples
The recipes below include complete programs and round-trip assertions. Examples
use the default std, compression, and decompression features unless stated
otherwise. The documentation workflow compiles and runs their Rust code against
the current checkout.
| Task | Recipe | Features / extra dependency |
|---|---|---|
| Choose graphs and compose codec nodes | Graphs · Codecs | Default; per-codec features |
| Preserve typed and multiple inputs | Structured data | Default |
| Set the level, format version and checksums | Encoder settings | Default |
| Write into a slice or uninitialized memory | Output buffers | Default |
| Decode untrusted input with limits | Set limits for untrusted input | Default |
| Read a frame header without decoding | Frame metadata | Default |
| Compress and decompress bytes | First round trip | Default |
| Reuse codec and destination memory | Reuse the workspace | Default |
| Write a raw stream incrementally | Stream through Write | Default |
| Drive a raw or framed encoder with tiny buffers | Sans I/O compression | Default; framed for frames |
| Decode arriving chunks and resource events | Sans I/O decompression | Default; framed for frames |
| Read or write raw, parallel, and framed streams | Read / Write I/O | Default; framed for frames |
| Use scoped CPU workers | Compressing a slice | Default |
| Reuse a Rayon thread pool | Running tasks with Rayon | Default + rayon |
| Stream through parallel workers | Reader and writer adapters | Default |
| Package compressed and stored resources | One container, two resources | framed |
| Add resource names and write incrementally | Write resources and metadata | framed |
| Read just the selected resource | Indexed resource reads | framed |
Run from the repository
Initialize the C reference submodule used by development builds:
git submodule update --init --recursive
cargo run --release --example compress
The parallel example uses caller-owned scoped threads, reuses its compressor and verifies every assembled frame:
cargo run --release --example parallel
For a parallel batch, all taken tasks must run or be dropped before finalization. For a streaming adapter, keep workers running while the adapter blocks. Finish ordinary/parallel writers and the enclosing framed container explicitly. Framed resource commands accept complete input rather than resource writer guards.
Verify the documented recipes
python3 scripts/docs.py test-examples
This creates a temporary Cargo consumer under target/, depends on the local
crate with framed enabled and on Rayon, and runs each fenced Rust program
from all user-guide chapters, including graphs, codecs, typed inputs, dictionaries,
parallel, framing and Sans I/O. It does not
exercise the codec with --all-features, because that would also enable no_std
and remove the std APIs these recipes demonstrate.