unityrs_core/env/registry/cab.rs
1//! What the registry answers a lookup with.
2
3use std::sync::Arc;
4
5use crate::files::{BundleFile, File, RawFile, SerializedFile};
6
7/// A registered CAB: what `get_cab` returns.
8#[derive(Clone, Debug)]
9pub enum Cab {
10 /// A `SerializedFile`.
11 Serialized(Arc<SerializedFile>),
12 /// A raw reader (`.resS`, `.resource`, name-rule files).
13 Raw(RawCab),
14}
15
16/// A raw CAB's bytes.
17#[derive(Clone, Debug)]
18pub enum RawCab {
19 /// A bundle entry, read through the bundle (no copy of the whole entry).
20 InBundle {
21 /// The bundle.
22 bundle: Arc<BundleFile>,
23 /// Its directory index.
24 dir_index: usize,
25 },
26 /// A file loaded on its own.
27 File(Arc<RawFile>),
28}
29
30/// A CAB with the handle that keeps its container alive: for a dependency's
31/// CAB, the dependency's top-level file as the lookup reached it (an
32/// eviction drops only the LRU's handle, so while this one is held the CAB's
33/// bundle, and with it the pointers that need its siblings, stay
34/// reachable); `None` for a CAB of a file the caller loaded, which is never
35/// evicted. What [`crate::env::Environment::get_cab_held`] returns.
36#[derive(Clone, Debug)]
37pub struct HeldCab {
38 /// The CAB.
39 pub cab: Cab,
40 /// The dependency's top-level file, when the CAB is a dependency's.
41 pub hold: Option<File>,
42}
43
44const _: () = crate::send_sync::<Cab>();
45const _: () = crate::send_sync::<RawCab>();
46const _: () = crate::send_sync::<HeldCab>();