Skip to main content

cubecl_environment/bundle/
base.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3
4use crate::bytes::Bytes;
5
6/// A read-only set of pre-computed cache entries shipped with an application.
7///
8/// Lookups use the same two coordinates as the local cache: the namespace the
9/// persistence layer computes (`<name>/<version>/<segments>`) and the
10/// serialized key bytes. A bundle therefore needs no path rewriting, and
11/// several bundles in different formats can be installed side by side.
12///
13/// A bundle is an *import* format, not a runtime one: [`import`](super::import)
14/// copies its entries into the local storage once, and nothing consults it
15/// afterwards. Runtime lookups only ever touch
16/// [`Storage`](crate::persistence::Storage).
17///
18/// Reads hand back [`Bytes`], which a format can serve as a zero-copy window
19/// into its own storage: an embedded bundle returns a view of its blob rather
20/// than a copy.
21///
22/// All methods degrade silently: a miss on any failure.
23pub trait Bundle: Send + Sync + core::fmt::Debug {
24    /// The value stored under `key` in `namespace`.
25    fn get(&self, namespace: &str, key: &[u8]) -> Option<Bytes>;
26
27    /// Visits every entry of `namespace`.
28    fn scan(&self, namespace: &str, visit: &mut dyn FnMut(&[u8], &[u8]));
29
30    /// Every namespace the bundle holds entries for.
31    fn namespaces(&self) -> Vec<String>;
32
33    /// Human-readable origin for log messages.
34    fn describe(&self) -> String;
35}