#struct #serialization #bit #deserialize

no-std deku

bit level serialization/deserialization proc-macro for structs

31 unstable releases

0.20.0 Oct 15, 2025
0.19.1 May 22, 2025
0.19.0 Apr 25, 2025
0.18.1 Sep 9, 2024
0.1.2 Mar 30, 2020

#39 in Encoding

Download history 68384/week @ 2025-07-19 65868/week @ 2025-07-26 70071/week @ 2025-08-02 60673/week @ 2025-08-09 57551/week @ 2025-08-16 66912/week @ 2025-08-23 71823/week @ 2025-08-30 73213/week @ 2025-09-06 68684/week @ 2025-09-13 65825/week @ 2025-09-20 74230/week @ 2025-09-27 95550/week @ 2025-10-04 93022/week @ 2025-10-11 83467/week @ 2025-10-18 74511/week @ 2025-10-25 52242/week @ 2025-11-01

324,353 downloads per month
Used in 70 crates (41 directly)

MIT/Apache

300KB
5K SLoC

Deku

Latest Version Rust Documentation Actions Status codecov

Declarative binary reading and writing

This crate provides bit-level, symmetric, serialization/deserialization implementations for structs and enums

Why use Deku

Productivity: Deku will generate symmetric reader/writer functions for your type! Avoid the requirement of writing redundant, error-prone parsing and writing code for binary structs or network headers

Usage

Compiler support: requires rustc 1.81+

[dependencies]
deku = "0.20"

no_std:

[dependencies]
deku = { version = "0.20", default-features = false, features = ["alloc"] }

Example

See documentation or examples folder for more!

Read big-endian data into a struct, modify a value, and write it

use deku::prelude::*;

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
#[deku(endian = "big")]
struct DekuTest {
    #[deku(bits = 4)]
    field_a: u8,
    #[deku(bits = 4)]
    field_b: u8,
    field_c: u16,
}

fn main() {
    let data: Vec<u8> = vec![0b0110_1001, 0xBE, 0xEF];
    let (_rest, mut val) = DekuTest::from_bytes((data.as_ref(), 0)).unwrap();
    assert_eq!(DekuTest {
        field_a: 0b0110,
        field_b: 0b1001,
        field_c: 0xBEEF,
    }, val);

    val.field_c = 0xC0FE;

    let data_out = val.to_bytes().unwrap();
    assert_eq!(vec![0b0110_1001, 0xC0, 0xFE], data_out);
}

Changelog

See CHANGELOG.md

Dependencies

~0.8–2MB
~40K SLoC