catalog.rs
cdk-rsx/crates/cdk-rsx-store/src/catalog.rs
1//! Complete catalogs for the ordinary Store root and its module tree.2use cdk_rsx_memory_abi::{Physical, RootedCatalog, physical, physical_type};34const DIRECTORY: Physical = physical::<crate::PhysicalDirectory>();5const HEAP: Physical = physical_type(cdk_rsx_engine_nyxus::allocator_layout_types()[0]);6const SLAB: Physical = physical_type(cdk_rsx_engine_nyxus::allocator_layout_types()[1]);7const PAGE: Physical = physical_type(cdk_rsx_engine_nyxus::allocator_layout_types()[2]);89/// A complete statically compiled module tree plus the Store/allocator kernel.10/// Build with `const CATALOG: Catalog = catalog::<root::memory::current::Memory>();`.11pub struct Catalog(RootedCatalog);12impl Catalog {13 pub fn module_count(&self) -> usize {14 self.0.module_count()15 }16 /// Include interpretation policies of external containers/custom code.17 /// The Store/allocator policies and all Nyxus/Hylix module contracts are18 /// automatic. This reads only freshly compiled metadata, never saved state.19 pub fn digest(&self, policies: &[[u8; 32]]) -> [u8; 32] {20 // Framing a separately composed kernel policy avoids a temporary Vec.21 let policy = cdk_rsx_memory_abi::catalog_digest(22 &[],23 &[],24 &[cdk_rsx_engine_nyxus::ALLOCATOR_POLICY, crate::MODULE_POLICY],25 );26 self.0.digest(27 &[&DIRECTORY, &HEAP, &SLAB, &PAGE],28 &[29 policy,30 cdk_rsx_memory_abi::catalog_digest(&[], &[], policies),31 ],32 )33 }34}3536/// Compile the closed module graph from a generated root declaration.37#[rustc_comptime]38pub fn catalog<M: cdk_rsx_memory_abi::CatalogSpec>() -> Catalog {39 Catalog(cdk_rsx_memory_abi::rooted::<M>())40}