Skip to main content

Cache/AssetMemoryMap/
Entry.rs

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