1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
# databake [](https://crates.io/crates/databake)
<!-- cargo-rdme start -->
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
```rust
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.
```rust
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.
```rust
test_bake!(
AnotherOne,
const,
crate::AnotherOne(
crate::MyStruct {
number: 17u32,
string: "foo",
slice: &[true, false],
},
'b',
),
my_crate,
);
```
<!-- cargo-rdme end -->
## More Information
For more information on development, authorship, contributing etc. please visit [`ICU4X home page`](https://github.com/unicode-org/icu4x).
|