| Crates.io | datalit |
| lib.rs | datalit |
| version | 0.1.0-alpha.4 |
| created_at | 2025-09-12 05:28:21.004621+00 |
| updated_at | 2025-09-14 19:26:49.059628+00 |
| description | A zero-runtime fluent data description macro |
| homepage | |
| repository | https://github.com/naerbnic/datalit |
| max_upload_size | |
| id | 1835197 |
| size | 24,994 |
datalitdatalit provides the datalit!(...) macro to turn a readable list of things
into real bytes at compile time. Highlights:
datalit can be added using the standard cargo add command:
$ cargo add datalit
...
In your code, you can use a datalit macro as an expression. This will resolve to a reference to a static array that contains the data described by the contents of the macro.
use datalit::datalit;
let data = datalit!(
// Hex / binary literals of any length (whole bytes) appended L->R.
0xDEAD_BEEF_CAFE_BABE,
0b0110_1111_1000_0100,
// Primitive integers: native endian by default.
1u32, 0x1FFu16,
// Explicit endianness via suffix or mode.
100u16_le,
@endian = be,
42u32, // big-endian now
// Non-standard width.
0x01_02_03u24_be,
// Strings / bytes.
b"quux", b'X', c"Hello, world!",
// Alignment to next multiple of 8 (pads with 0x00)
align(8),
// A labeled block and offset expressions.
start('payload): u16_le,
'payload: {
12u16,
b"PAY",
},
end('payload): u16_le,
len('payload): u16_le,
// Simple & compound arrays.
[ 0xFF; 4 ],
[{ 0xAA, 0xBB }; 2],
);
assert!(data.len() > 0);
Contributions are welcome! If you’ve got a bug report, idea, or small fix:
Before you open a PR, please:
no_std and forbid(unsafe_code) guarantees intact.See CONTRIBUTING.md for details on the workflow and guidelines.
This project is dual-licensed under either the MIT or Apache 2.0 license, at your option.
You may use this project under the terms of either license.
Please do not report vulnerabilities in public issues. For private disclosure instructions, see SECURITY.md.
Thanks to the Rust macros and tooling ecosystem—particularly syn, quote, and proc-macro2—for making ergonomic proc-macros possible.
And thanks in advance to contributors for bug reports, ideas, and reviews.