Mountain/Cache/AssetMemoryMap/Entry.rs
1
2//! Single MemoryMap-backed asset cache entry. Holds the file-backed mapping
3//! plus metadata computed once at load time.
4
5use memmap2::Mmap;
6
7pub struct Struct {
8 /// The MemoryMap mapping itself. Keep alive as long as any webview body
9 /// references it.
10 pub Mapping:Mmap,
11
12 /// Cached MIME from the file extension. Avoids the match arm on the hot
13 /// path.
14 pub Mime:&'static str,
15
16 /// File size at MemoryMap time. Used for `Content-Length`.
17 pub Length:usize,
18
19 /// Optional pre-brotli-compressed sibling (path with `.br` suffix). `None`
20 /// if no sibling existed at load time.
21 pub Brotli:Option<Mmap>,
22}
23
24impl Struct {
25 /// Borrow the entire mapping as a slice. Caller keeps `Arc<Struct>` alive
26 /// for the lifetime of any response body that captures the slice.
27 pub fn AsSlice(&self) -> &[u8] { &self.Mapping[..] }
28
29 /// Borrow the brotli-precompressed sibling if present.
30 pub fn AsBrotliSlice(&self) -> Option<&[u8]> { self.Brotli.as_ref().map(|M| &M[..]) }
31
32 /// Length of the brotli sibling. Useful for `Content-Length` when serving
33 /// the precompressed payload.
34 pub fn BrotliLength(&self) -> Option<usize> { self.Brotli.as_ref().map(|M| M.len()) }
35}