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

#491 in Build Utils

Download history 1216/week @ 2023-12-09 1368/week @ 2023-12-16 979/week @ 2023-12-23 982/week @ 2023-12-30 1317/week @ 2024-01-06 1335/week @ 2024-01-13 1352/week @ 2024-01-20 1662/week @ 2024-01-27 1775/week @ 2024-02-03 1854/week @ 2024-02-10 1601/week @ 2024-02-17 1552/week @ 2024-02-24 1853/week @ 2024-03-02 1913/week @ 2024-03-09 1744/week @ 2024-03-16 1577/week @ 2024-03-23

7,326 downloads per month
Used in 19 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