4 releases

0.1.3 Jan 26, 2023
0.1.2 Aug 4, 2022
0.1.1 Jul 11, 2022
0.1.0 Jun 28, 2022

#32 in Procedural macros

Download history 162/week @ 2022-12-09 89/week @ 2022-12-16 145/week @ 2022-12-23 68/week @ 2022-12-30 129/week @ 2023-01-06 64/week @ 2023-01-13 412/week @ 2023-01-20 198/week @ 2023-01-27 300/week @ 2023-02-03 137/week @ 2023-02-10 255/week @ 2023-02-17 214/week @ 2023-02-24 338/week @ 2023-03-03 252/week @ 2023-03-10 209/week @ 2023-03-17 271/week @ 2023-03-24

1,097 downloads per month
Used in 27 crates (23 directly)

Unicode-DFS-2016

16KB
294 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 uses to assert that a particular expression is a Bake fixed point.

## 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);
## fn main() {
test_bake!(
    AnotherOne,
    const: crate::AnotherOne(
        crate::MyStruct {
          number: 17u32,
          string: "foo",
          slice: &[true, false],
        },
        'b',
    ),
    my_crate,
);
## }
```rust

## More Information

For more information on development, authorship, contributing etc. please visit [`ICU4X home page`](https://github.com/unicode-org/icu4x).

Dependencies

~0.7–1.1MB
~28K SLoC