The Slice codec (slice-codec)
slice-codec is a lightweight library for encoding and decoding values using the Slice encoding.
Overview
The codec is built around two pairs of types:
Encoderwrites values into anOutputTarget, driven by theEncodeIntotrait.Decoderreads values out of anInputSource, driven by theDecodeFromtrait.
Implementations of EncodeInto / DecodeFrom are provided for common primitives and collections,
but you can implement these traits on your own types to make them usable with Slice.
Example
use Encoder;
use Decoder;
Using slice-codec in a Cargo Project:
Add slice-codec as a dependency to your project's Cargo.toml file:
[]
= "0.4"
Usage in no_std Projects
The codec is no_std compatible, so it can be used in embedded or other constrained environments.
To use the codec in a no_std project, just disable default features:
[]
= { = "0.4", = false }
If you have a global allocator and need to decode owned types like String or Vec, also enable the alloc feature.
Feature Flags
| Feature | Default | Description |
|---|---|---|
std |
✅ | Enables implementations to encode/decode standard-library types such as String, Vec, and HashMap. Implies alloc. |
alloc |
✅ | Enables implementations to decode dynamically-allocated types like String and Vec. Intended for no_std + global allocator. |
Building
This crate is part of the slicec workspace.
Commands should be run from the repository root:
# Build with the default features.
cargo build -p slice-codec
# Run the tests with all features enabled.
cargo test -p slice-codec --all-features
License
'slicec-codec' is licensed under the Apache License, Version 2.0.