8 releases

0.1.7 Nov 16, 2023
0.1.6 Sep 22, 2023
0.1.5 Apr 24, 2023
0.1.3 Jan 26, 2023
0.1.0 Jun 28, 2022

#31 in Procedural macros

Download history 826/week @ 2024-01-01 986/week @ 2024-01-08 702/week @ 2024-01-15 801/week @ 2024-01-22 907/week @ 2024-01-29 1488/week @ 2024-02-05 1375/week @ 2024-02-12 1549/week @ 2024-02-19 1435/week @ 2024-02-26 1423/week @ 2024-03-04 1988/week @ 2024-03-11 1671/week @ 2024-03-18 1771/week @ 2024-03-25 1720/week @ 2024-04-01 1934/week @ 2024-04-08 1811/week @ 2024-04-15

7,294 downloads per month
Used in 31 crates (29 directly)

Custom license

21KB
458 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

~205KB