Skip to main content

Mountain/Cache/AssetMemoryMap/
Entry.rs

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