include_data - Include typed data directly in your executable

Stability

While this crate is pre-1.0 you should consider both the API and semantics unstable. However, this is simply to allow thorough community-review of the soundness of implementation. I hope that a 1.0 release will come relatively quickly with few API changes.

Including data

Sometimes, you want to include data directly in your executable file, but you don't want to translate that data into Rust cod that does the static initialization. This is very useful in embedded contexts, or if you have some (usually relatively small) data that will always be needed, and you don't want to deal with loading it from the filesystem and distributing it as a separate file.

The Rust standard library (and core library) contains [include_bytes][core::include_bytes] for this purpose. This macro will give you a static reference to a binary array containing the data from a file: that is, a &'static [u8; N].

However, if you want to use your static data, you often want it to be of a particular type, not just a [u8]. For example, you may know that your included file is a sequence of f64s, or a UTF-32 file, or of some custom type. This crate provides macros for typed compile-time data includes. This is provided by two main macros: