#array #static #macro #byte #definition #produces #include-bytes

no-std static-include-bytes

Like the built-in include_bytes! macro but produces a static array definition

2 stable releases

2.0.0 Aug 20, 2023
1.0.1 Aug 19, 2023

#2302 in Rust patterns

34 downloads per month

MIT license

4KB

static_include_bytes! Macro

Crates.io docs.rs

Like the built-in include_bytes! macro, but produces a static array definition.

Example

use static_include_bytes::static_include_bytes;

static_include_bytes!(#[no_mangle] TEN_BYTES = concat!(env!("CARGO_MANIFEST_DIR"), "/ten_bytes.bin"));

assert_eq!(TEN_BYTES.len(), 10);
assert_eq!(&TEN_BYTES, b"0123456789");

The macro invocation is equivalent to static TEN_BYTES: [u8; _] = include_bytes!(...);, but as of 2023-08-18, you cannot write this directly due to https://github.com/rust-lang/rust/issues/85077 .

No runtime deps