Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomaka/pocket-resources
https://github.com/tomaka/pocket-resources
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tomaka/pocket-resources
- Owner: tomaka
- License: mit
- Created: 2015-03-27T15:25:14.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-29T07:58:30.000Z (10 months ago)
- Last Synced: 2024-04-26T17:13:15.471Z (9 months ago)
- Language: Rust
- Size: 12.7 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# Pocket-resources
## Usage
See the demo crate.
Tweak your Cargo.toml to use a build script:
```toml
[package]
# ...
build = "build.rs"[build-dependencies]
pocket-resources = "*"
```Create a `build.rs` file:
```rust
extern crate pocket_resources;fn main() {
pocket_resources::package(&[("resources","path/to/image.png")]).unwrap();
}
```Include the resources where you want:
```rust
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:
```rust
let data: &[u8] = ResourceId::PathToImagepng.load();
```Or load it at runtime:
```rust
let data: &[u8] = ResourceId::from_name("path/to/image.png").unwrap().load();
```