9 releases

Uses old Rust 2015

0.3.2 Jan 2, 2016
0.3.1 Dec 6, 2015
0.2.2 Aug 5, 2015
0.2.1 May 15, 2015
0.1.0 Mar 27, 2015

#630 in Build Utils

Download history 2141/week @ 2024-08-04 2720/week @ 2024-08-11 2586/week @ 2024-08-18 2172/week @ 2024-08-25 2457/week @ 2024-09-01 2443/week @ 2024-09-08 2651/week @ 2024-09-15 2905/week @ 2024-09-22 2890/week @ 2024-09-29 2909/week @ 2024-10-06 3760/week @ 2024-10-13 3546/week @ 2024-10-20 4191/week @ 2024-10-27 3200/week @ 2024-11-03 3234/week @ 2024-11-10 3056/week @ 2024-11-17

14,040 downloads per month
Used in 24 crates (2 directly)

MIT license

9KB
150 lines

Pocket-resources

Usage

See the demo crate.

Tweak your Cargo.toml to use a build script:

[package]
# ...
build = "build.rs"

[build-dependencies]
pocket-resources = "*"

Create a build.rs file:

extern crate pocket_resources;

fn main() {
    pocket_resources::package(&["resources"]).unwrap();
}

Include the resources where you want:

include!(concat!(env!("OUT_DIR"), "/pocket-resources.rs"));

This creates a public enum named Resource. If you want to name it something else, or if you want it private, you should use a module.

You can then load the resource directly from the enum:

let data: &[u8] = Resource::PathToImagePng.load();

Or load it at runtime:

let data: &[u8] = Resource::from_name("path/to/image.png").unwrap().load();

No runtime deps