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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! # grouse
//!
//! A simple asset bundler for Rust.
//!
//! ## about
//!
//! `grouse` is a very simple asset bundler intended for baking static web
//! content directly into your Rust binaries. This library can be thought of a more
//! specialized version of the fantastic `include_dir` crate; Whilst
//! `include_dir` provides a more traditional tree-like view of the embedded assets,
//! `grouse` uses `sha256` to generate a digest of each file and provides a flat,
//! hashmap-like view of digest, file pairs. This is particularly useful when
//! serving static web content, as changes to any files will effectively change the
//! name of that file being served, and invalidate any browser caches.
//!
//! ## getting started
//!
//! To start using `grouse`, you'll first need to add our package to your
//! `Cargo.toml` manifest:
//!
//! ```sh
//! cargo add grouse
//! ```
//!
//! Then you can bundle a directory into your Rust executable.
//!
//! ```rust
//! # use grouse::{Manifest, File};
//!
//! // Thanks to recently stablized proc-macro features, the include
//! // path is relative to the current file directory, like how the
//! // builtin [`core::include_bytes!`] macro works.
//! const MANIFEST: Manifest<'static> = grouse::include!("../src");
//!
//! fn main() {
//! // Iterate through all of the files in the manifest.
//! for file in MANIFEST {
//! eprintln!("{} => {}", file.name(), file.digest());
//! }
//!
//! // We can also get the digest of a particular file.
//! let x = grouse::digest!("../src/lib.rs");
//!
//! // Which can then be used to lookup it's corresponding file in the
//! // manifest.
//! let lib = MANIFEST.get(x).unwrap();
//! }
//! ```
pub use ;
/// A flat, hashmap-like container for all of the files included using
/// [`grouse::include!`]. This means that any subdirectories are flattened, and
/// all files are identified by their unique sha2 digest.
///
/// The path of each file is not included within this digest, which means that
/// any files with the exact same content, regardless of their subdirectory
/// or name, will be merged into a single file entry. In this case, the name
/// reported by [`File::name`] is undefined behaviour.
///
/// ## remarks
///
/// The fields of this struct are `pub` so that it can be initialized by the
/// [`grouse::include!`] macro, however, they are considered a private API for the
/// most part. Therefore, it is highly discouraged to directly access these fields
/// and their name must not be relied upon across versions.
/// Represents a single file within a [`Manifest`].
///
/// ## remarks
///
/// The fields of this struct are `pub` so that it can be initialized by the
/// [`grouse::include!`] macro, however, they are considered a private API for the
/// most part. Therefore, it is highly discouraged to directly access these fields
/// and their name must not be relied upon across versions.