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
//! Embed content-hashed static web assets into your binary and serve them with `tower`.
//!
//! `tower-serve-embedded` is similar to [`rust-embed`](https://docs.rs/rust-embed) but tailored
//! for *serving* web assets from a `tower`/`axum` stack: every file is embedded and exposed at a
//! content-hashed URL that mirrors its location in your crate
//! (`assets/css/style.css` → `/assets/css/style.9f3a1c2b.css`), so it can be served `immutable`
//! with a one-year cache and still update instantly when its content changes.
//!
//! # How it works
//!
//! The heavy lifting (walking the directory, hashing, MIME detection, codegen) happens at build
//! time in [`tower-serve-embedded-build`](https://docs.rs/tower-serve-embedded-build), called
//! from your `build.rs`. There are **no proc macros** — the generated code is plain data plus a
//! tiny `macro_rules!`, so IDE support stays excellent.
//!
//! ```ignore
//! // build.rs
//! fn main() {
//! tower_serve_embedded_build::Builder::new("assets").emit().unwrap();
//! }
//! ```
//!
//! ```ignore
//! // src/main.rs
//! tower_serve_embedded::embed!(); // pulls in `ASSETS` and the `asset!` macro
//!
//! // Reference assets by their path relative to the crate root. Resolved at compile time —
//! // typos are compile errors:
//! // link rel="stylesheet" href=(asset!("assets/css/style.css"))
//! // => "/assets/css/style.9f3a1c2b.css"
//!
//! // Serve them: the embedded path is already the full URL, so mount the service as a fallback.
//! // Router::new().fallback_service(ASSETS.service())
//! ```
//!
//! See `examples/` in the repository for complete, runnable setups (`axum`, `actix`, `warp`).
pub use ServeEmbedded;
/// A single embedded asset: its content plus the metadata needed to serve it.
///
/// Values of this type are generated at build time and stored in a `static` slice; you do not
/// construct them by hand.
/// A collection of [`EmbeddedFile`]s.
///
/// You normally get one via the generated `ASSETS` static (see [`embed!`]), not by calling
/// [`Assets::new`] yourself.
/// Pull in the assets generated by `tower-serve-embedded-build`.
///
/// Call this once at module scope (typically in `main.rs`). It expands to an `include!` of the
/// build script's generated file, bringing into scope:
///
/// - `pub static ASSETS: tower_serve_embedded::Assets` — the embedded asset set, and
/// - `macro_rules! asset` — a compile-time macro mapping a crate-root-relative path to its URL.
///
/// ```ignore
/// tower_serve_embedded::embed!();
///
/// fn css() -> &'static str { asset!("assets/css/style.css") } // "/assets/css/style.9f3a1c2b.css"
/// ```