macro

include_bytes! — Embed raw file bytes

Embed bytes without requiring valid UTF-8. The result is a reference to a fixed-size array whose length equals the file length. It can coerce to a byte slice. Useful for small static assets; large assets may increase executable size. Result: &'static [u8; N]. Fixture prerequisites: header.bin (see catalog for exact contents). Expected output (not executed): '[00, FF, 2A]\n' Common mistake: Assuming every embedded byte sequence is a valid string.

Formal Syntax & Structure

rust syntaxrust
include_bytes!("relative/path.bin")

Working Example

Example Snippetrust
fn main() {    let bytes: &'static [u8; 3] = include_bytes!("header.bin");    println!("{:02X?}", bytes);}
Rust Reference