Debian Codegraph @

README.md

raw symbols SCIP
1 # Pocket-resources
2
3 ## Usage
4
5 See the demo crate.
6
7 Tweak your Cargo.toml to use a build script:
8
9 ```toml
10 [package]
11 # ...
12 build = "build.rs"
13
14 [build-dependencies]
15 pocket-resources = "*"
16 ```
17
18 Create a `build.rs` file:
19
20 ```rust
21 extern crate pocket_resources;
22
23 fn main() {
24 pocket_resources::package(&["resources"]).unwrap();
25 }
26 ```
27
28 Include the resources where you want:
29
30 ```rust
31 include!(concat!(env!("OUT_DIR"), "/pocket-resources.rs"));
32 ```
33
34 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.
35
36 You can then load the resource directly from the enum:
37
38 ```rust
39 let data: &[u8] = Resource::PathToImagePng.load();
40 ```
41
42 Or load it at runtime:
43
44 ```rust
45 let data: &[u8] = Resource::from_name("path/to/image.png").unwrap().load();
46 ```