static_assets 0.1.1

Macros for statically including assets in release mode, but dynamically loading them in debug mode. This is primarily intended for games, allowing you to both avoid file IO in release builds and dynamically reload assets in debug mode.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented0 out of 2 items with examples
  • Size
  • Source code size: 9.48 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.19 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • mistodon/static_assets
    7 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mistodon

NOTE: This project has been renamed

GitHub repo is here: https://github.com/mistodon/resource Crate is here: https://crates.io/crates/resource

If anyone happens to want the static_assets crate name, feel free to contact me and I'll hand it over.

static_assets

The static_assets crate contains macros for statically including assets in release mode, but dynamically loading them in debug mode.

This is primarily intended for games, allowing you to both avoid file IO in release builds and dynamically reload assets in debug mode.

Usage

[dependencies]
static_assets = "~0.1.0"
#[macro_use]
extern crate static_assets;

let text = asset_str!("assets/text_asset.txt");
println!("Text is: {}", text);

let bytes = asset_bytes!("assets/binary_asset.bin");
println!("Binary data is: {:?}", bytes);

Internals

The asset_str! and asset_bytes! macros return Cow values - Cow<'static, str> and Cow<'static, [u8]> respectively.

If you're not familiar with the Cow type, what this means is that under the hood, they can be either a reference to some const data (in release mode) or some actual owned data on the heap (in debug mode).

You shouldn't have to care about this though because the above Cow types can deref to &str and &[u8] respectively. Just pass them by reference and treat them as strings/slices.