static_include_bytes/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3
4/// Inserts a static byte array definition with both its content and length loaded from a file at
5/// compile time. `static_include_bytes!(#[attr] NAME = PATH)` is semantically equivalent to
6/// `#[attr] static NAME: [u8; _] = *include_bytes!(PATH);` which you cannot write directly as of 2023-08-18
7/// due to <https://github.com/rust-lang/rust/issues/85077> .
8///
9/// # Example
10///
11/// ```rust
12/// use static_include_bytes::static_include_bytes;
13///
14/// static_include_bytes!(#[no_mangle] TEN_BYTES = concat!(env!("CARGO_MANIFEST_DIR"), "/ten_bytes.bin"));
15///
16/// assert_eq!(TEN_BYTES.len(), 10);
17/// assert_eq!(&TEN_BYTES, b"0123456789");
18/// ```
19///
20#[macro_export]
21macro_rules! static_include_bytes {
22    ($(#[$m:meta])* $name:ident = $path:expr) => {
23        $(#[$m])*
24        static $name: [u8; include_bytes!($path).len()] = *include_bytes!($path);
25    };
26}