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
//! Embedded file provider trait and global registry.
//!
//! This module allows user applications to register their own `rust-embed`-backed
//! file stores (for views and static assets) so that the framework can serve them
//! at runtime without knowing the concrete type at compile time.
//!
//! ## Usage (generated by `auto_discover` macro)
//!
//! ```rust,ignore
//! #[derive(RustEmbed)]
//! #[folder = "views/"]
//! struct AppViews;
//!
//! impl EmbeddedFileProvider for AppViews {
//! fn get(&self, path: &str) -> Option<Vec<u8>> { ... }
//! fn files(&self) -> Vec<String> { ... }
//! }
//!
//! register_views_provider(Box::new(AppViews));
//! register_assets_provider(Box::new(AppAssets));
//! ```
use OnceLock;
/// A runtime-erased provider for files embedded via `rust-embed`.
///
/// Implement this trait on your `RustEmbed`-derived struct.
// ─── Global registries ───────────────────────────────────────────────────────
static VIEWS_PROVIDER: = new;
static ASSETS_PROVIDER: = new;
/// Register the application's embedded views provider.
///
/// Call once at startup (the `auto_discover` macro does this automatically).
/// Calling more than once is a no-op (the first registration wins).
/// Register the application's embedded static-assets provider.
///
/// Call once at startup (the `auto_discover` macro does this automatically).
/// Calling more than once is a no-op (the first registration wins).
/// Get a reference to the registered views provider, if any.
/// Get a reference to the registered assets provider, if any.