apalis-codec
apalis-codec provides encoding and decoding strategies for task arguments, results, and other values used by backends.
This crate exposes a small, backend-independent [Codec] trait and optional implementations for common serialization formats.
Features
The following codecs are available behind feature flags:
json— JSON encoding usingserde_jsonmsgpack— MessagePack encoding usingrmp-serdebincode— Binary encoding usingbincode
No codec implementation is enabled by default.
Codec
The [Codec] trait defines the interface between a value and its compact representation:
The Compact type is intentionally left up to the codec. Depending on the implementation, it may be a byte buffer, a string, or another representation suitable for storage or transmission.
Available Codecs
JSON
Enable the json feature:
[]
= { = "...", = ["json"] }
JSON is useful when human-readable representations or interoperability with other systems are important.
MessagePack
Enable the msgpack feature:
[]
= { = "...", = ["msgpack"] }
MessagePack provides a compact binary representation while retaining broad serialization compatibility.
Bincode
Enable the bincode feature:
[]
= { = "...", = ["bincode"] }
Bincode provides a compact binary representation suitable for applications where storage size and serialization performance are important.
Choosing a Codec
The appropriate codec depends on how tasks are stored or transported:
| Codec | Representation | Human-readable | Typical use |
|---|---|---|---|
| JSON | Text | Yes | APIs, debugging, interoperability |
| MessagePack | Binary | No | Compact storage and network transport |
| Bincode | Binary | No | Efficient Rust-native serialization |
For distributed task queues, MessagePack or Bincode are generally preferable when compact binary representations are desired. JSON can be useful when tasks need to be inspected or consumed by systems outside the Rust ecosystem.
Serde
The codec implementations are designed around serde. Values generally need to implement the appropriate Serialize and Deserialize traits.
For example:
use ;
The same task type can then be encoded using different codecs without changing the task itself.
Feature Flags
[]
= ["serde_json"]
= ["rmp-serde"]
= ["bincode"]
Select only the formats required by your application to avoid unnecessary dependencies.
License
Licensed under either of:
- Apache License, Version 2.0
- MIT License
at your option.