DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Cache/AssetMemoryMap/Entry.rs
1//! Single MemoryMap-backed asset cache entry. Holds the file-backed mapping
2//! 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 body
8 /// references it.
9 pub Mapping:Mmap,
10
11 /// Cached MIME from the file extension. Avoids the match arm on the hot
12 /// 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` suffix). `None`
19 /// 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 `Arc<Struct>` alive
25 /// for the lifetime of any response body that captures the slice.
26 pub fn AsSlice(&self) -> &[u8] { &self.Mapping[..] }
27
28 /// Borrow the brotli-precompressed sibling if present.
29 pub fn AsBrotliSlice(&self) -> Option<&[u8]> { self.Brotli.as_ref().map(|M| &M[..]) }
30
31 /// Length of the brotli sibling. Useful for `Content-Length` when serving
32 /// the precompressed payload.
33 pub fn BrotliLength(&self) -> Option<usize> { self.Brotli.as_ref().map(|M| M.len()) }
34}