#resources

pocket-resources

Include resources in your applications

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

#140 in Build Utils

Download history 909/week @ 2022-06-10 892/week @ 2022-06-17 1042/week @ 2022-06-24 736/week @ 2022-07-01 759/week @ 2022-07-08 940/week @ 2022-07-15 642/week @ 2022-07-22 806/week @ 2022-07-29 1110/week @ 2022-08-05 1044/week @ 2022-08-12 1165/week @ 2022-08-19 979/week @ 2022-08-26 1129/week @ 2022-09-02 1731/week @ 2022-09-09 1764/week @ 2022-09-16 1187/week @ 2022-09-23

5,909 downloads per month
Used in 12 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