nibblet

Crates.ionibblet
lib.rsnibblet
version0.1.0
created_at2025-06-08 03:59:12.588549+00
updated_at2025-06-08 03:59:12.588549+00
descriptionByte-focussed alternative ser/de derives
homepage
repositoryhttps://github.com/TheMikeste1/discrimin-ant
max_upload_size
id1704593
size73,377
Michael Hegerhorst (TheMikeste1)

documentation

README

Nibblet

Nibblet is a byte-focussed alternative ser/de derives.


Serde is a fantastic library for serializing data into multiple formats, including binary formats such as bincode and postcard. However, the default serialize and deserialize derives in Serde make cross-application/language use of these formats difficult.

Examples:

  • bincode explicitly ignores the repr for an enum
  • Serde only passes the variant index when calling serialize_*_variant (the serialize methods for enums)
    • Applications and ICDs often require specific values, not indices
    • The index may change as develop continues, requiring updates to external code relying on the marshalled format
    • This makes it difficult to serialize the actual discriminant because that information is not passed
  • Constant-sized arrays larger than 32 are serialized as a sequence, just like dynamic sized arrays

This crate attempts to resolve these issues by providing alternative Serialize and Deserialize derives. These derives are specifically designed to work with binary formats, and may not be compatible with other formats.

To use these alternative derives, just use the nibblet versions instead of the serde versions:

use discrimin_ant_proc::discriminant;
use nibblet::Serialize;

#[derive(Serialize)]
#[discriminant(u8)] // Enums must provide a discriminant implementation
enum FieldTypes {
    Unit,
    Newtype(u8),
    Unnamed(u8, u16),
    Field{ a: u8, b: u16 },
}
Commit count: 4

cargo fmt