11 releases

new 0.2.1 Apr 1, 2026
0.2.0 Nov 23, 2024
0.1.8 May 28, 2024
0.1.7 Nov 16, 2023
0.1.1 Jul 11, 2022

#84 in Procedural macros

Download history 1276/week @ 2025-12-10 2694/week @ 2025-12-17 1520/week @ 2025-12-24 3483/week @ 2025-12-31 3138/week @ 2026-01-07 2618/week @ 2026-01-14 2933/week @ 2026-01-21 4521/week @ 2026-01-28 6025/week @ 2026-02-04 5302/week @ 2026-02-11 6063/week @ 2026-02-18 6426/week @ 2026-02-25 12533/week @ 2026-03-04 15203/week @ 2026-03-11 7784/week @ 2026-03-18 8831/week @ 2026-03-25

45,929 downloads per month
Used in 59 crates (40 directly)

Unicode-3.0

33KB
749 lines

databake crates.io

This crate allows data to write itself into Rust code (bake itself in).

Types that implement the Bake trait can be written into Rust expressions, which allows using Rust code itself as a zero-overhead "serialization" strategy.

Example

use databake::*;
use alloc::borrow::Cow;

let data = [Some((18, Cow::Borrowed("hi")))];
assert_eq!(
    data.bake(&Default::default()).to_string(),
    r#"[Some ((18i32 , alloc :: borrow :: Cow :: Borrowed ("hi")))]"#,
);

Derive

Bake can be automatically derived if the derive Cargo feature is enabled.

use databake::*;

#[derive(Bake)]
#[databake(path = my_crate)]
struct MyStruct {
    pub number: u32,
    pub string: &'static str,
    pub slice: &'static [bool],
}

#[derive(Bake)]
#[databake(path = my_crate)]
struct AnotherOne(pub MyStruct, pub char);

Testing

The test_bake macro can be used to assert that a particular expression is a Bake fixed point.

test_bake!(
    AnotherOne,
    const,
    crate::AnotherOne(
        crate::MyStruct {
            number: 17u32,
            string: "foo",
            slice: &[true, false],
        },
        'b',
    ),
    my_crate,
);

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.

Dependencies

~135KB