aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 96d8dc6e5f47bcc519954230aad7c01f4e349711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
includedir
===========

[![Travis](https://img.shields.io/travis/tilpner/includedir.svg?style=flat-square)](https://travis-ci.org/tilpner/includedir)
[![Appveyor](https://img.shields.io/appveyor/ci/tilpner/includedir.svg?label=appveyor&style=flat-square)](https://ci.appveyor.com/project/tilpner/includedir)
[![Crates.io version](https://img.shields.io/crates/v/includedir.svg?style=flat-square)](https://crates.io/crates/includedir)
[![docs.rs](https://docs.rs/includedir/badge.svg)](https://docs.rs/includedir)
[![Crates.io license](https://img.shields.io/crates/l/includedir.svg?style=flat-square)](https://crates.io/crates/includedir)

Include a directory in your Rust binary, e.g. static files for your web server or assets for your game.

## Features

* [x] Automatically compile data into binary
* [x] Use [rust-phf](https://github.com/sfackler/rust-phf) for efficient lookup
* [x] Wrapping API around the phf map, to abstract away additional features
* [x] Compression, with optional crate "flate2"
* [x] Reading from source files for debug builds
* [ ] Tested on non-Linux platforms. Passthrough won't work on Windows, the rest should.

## Example

**Cargo.toml**
```toml
[package]
name = "example"
version = "0.1.0"

build = "build.rs"
include = ["data"]

[dependencies]
phf = "0.7.12"
includedir = "0.2.0"

[build-dependencies]
includedir_codegen = "0.2.0"
```

**build.rs**

```rust
extern crate includedir_codegen;

use includedir_codegen::Compression;

fn main() {
    includedir_codegen::start("FILES")
        .dir("data", Compression::Gzip)
        .build("data.rs")
        .unwrap();
}
```

**src/main.rs**

```rust
extern crate includedir;
extern crate phf;

include!(concat!(env!("OUT_DIR"), "/data.rs"));

fn main() {
    println!("{:?}", FILES.get("data/foo"))
}
```