Serbia
Serde big arrays. An attribute macro to make (de)serializing big arrays painless, roughly following a design proposed by David Tolnay.
Why?
I saw the idea in request-for-implementation. Then I came up with the name.
The name was too good. I had to do it. Don't judge me.
Also: Serbia has some tasty food.
But what is it for?
Serde only implements Serialize
/Deserialize
for arrays of length up to 32. This is due to Rust's current limitation - we can't be generic over array length, so
an arbitrary upper limit was chosen and implementations were generated only up to it.
The crate provides a macro that generates all the code you need to (de)serialize arrays bigger than that.
Status
Under development, but functional. Let me know what's missing or broken!
Usage
Just slap #[serbia]
on top of your type definition. Structs and enums both work!
use serbia;
If Serbia sees an array length given as a constant, it will generate custom serialize/deserialize code by default, without inspecting whether the constant is larger than 32 or not. This is a limitation of macros.
const BUFSIZE: usize = 22;
Skipping fields
If for some reason you don't want Serbia to generate custom serialize/deserialize code for a field that it would normally handle, you can skip it.
const BUFSIZE: usize = 24;
It's possible to be more granular if needed for some reason.
const BUFSIZE: usize = 24;
Manual array length
You can use the #[serbia(bufsize = ... )]
option to set an array length for
a field. This can be useful to make type aliases work. Constants work here!
type BigArray = ;
const BUFSIZE: usize = 300;
type BigArray = ;
Interaction with Serde field attributes
Serbia detects when certain Serde field attributes are used and avoids generating code that would cause a conflict, instead yielding to Serde.
Serbia is intended to play nice with Serde field attributes. If there are problems, please create an issue or submit a PR!
What doesn't work
Nested types.
Serbia doesn't yet pick up on Serde variant attributes,
so there might be conflicts there. This can probably be worked around by using
#[serbia(skip)]
on each field that Serbia would try to generate custom
(de)serialization code for.