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