10 releases

0.2.0 Nov 23, 2024
0.1.8 May 28, 2024
0.1.7 Nov 16, 2023
0.1.5 Apr 24, 2023
0.1.1 Jul 11, 2022

#36 in Procedural macros

Download history 2017/week @ 2024-08-23 2200/week @ 2024-08-30 1877/week @ 2024-09-06 1457/week @ 2024-09-13 2521/week @ 2024-09-20 2194/week @ 2024-09-27 1454/week @ 2024-10-04 1934/week @ 2024-10-11 2382/week @ 2024-10-18 2403/week @ 2024-10-25 2229/week @ 2024-11-01 1810/week @ 2024-11-08 2337/week @ 2024-11-15 2577/week @ 2024-11-22 3150/week @ 2024-11-29 860/week @ 2024-12-06

9,275 downloads per month
Used in 46 crates (34 directly)

Unicode-3.0

31KB
731 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 {
    number: u32,
    string: &'static str,
    slice: &'static [bool],
}

#[derive(Bake)]
#[databake(path = my_crate)]
struct AnotherOne(MyStruct, 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

~175KB