datalit
Overview
datalit provides the datalit!(...) macro to turn a readable list of things
into real bytes—at compile time. Highlights:
- Readable data: Hard to read raw byte arrays? Describe intent with readable literals.
- Endian aware: Unsure about byte order? Declare it once; the macro handles the rest.
- Offsets: Tired of recalculating offsets? Labels and offset expressions update themselves.
- Concise: Spending time on padding & length management? Built-ins remove the manual bookkeeping.
- Zero cost at runtime: Worried about hidden cost or mistakes? Your data is validated at compile time, and expands to one static slice.
Installation
datalit can be added using the standard cargo add command:
$ cargo add datalit
...
Usage
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.
Examples
use datalit;
let data = datalit!;
assert!;
Contributing
TBD.
License
This project is dual-licensed under either the MIT or Apache 2.0 license, at your option.
- See LICENSE-MIT for the MIT license text.
- See LICENSE-APACHE for the Apache 2.0 license text.
You may use this project under the terms of either license.
Acknowledgements
TBD.
Future work
- Allow for scoped labels, so they can be used in compound arrays.
- Add basic math operators, so things like relative offsets or the like can be computed.
- Allow for alignment to define the fill byte (or make it part of the mode)
- Implement scoped modes, so mode changes within a block can be made without affecting the outside state.
- Allow for some relatively common specialized operations, such as CRCs
- Allow labeled range offsets to be exported along with the data so runtime code can use it as needed.
- Support for strings, including with multiple encodings
- Syntax: Have a paren-wrapped entry be treated as an expression (with function calling as a special case)