snix_store/composition.rs
1//! This module provides a registry knowing about {Blob,Directory,PathInfo}
2//! Services, as well as the [add_default_services] helper to seed new
3//! registries with everything known here.
4//! The composition machinery itself is defined in
5//! [snix_castore::composition], which works generically with different kinds
6//! of services.
7
8use std::sync::LazyLock;
9
10use snix_castore::composition::Registry;
11
12/// The provided registry of snix_store, which has all the builtin
13/// snix_castore (BlobStore/DirectoryStore) and snix_store
14/// (PathInfoService) implementations.
15pub static REG: LazyLock<&'static Registry> = LazyLock::new(|| {
16 let mut reg = Default::default();
17 add_default_services(&mut reg);
18 // explicitly leak to get an &'static, so that we gain `&Registry: Send` from `Registry: Sync`
19 Box::leak(Box::new(reg))
20});
21
22/// Register the builtin services of snix_castore (blob services and directory
23/// services), as well as the ones from snix_store (PathInfo service) with the
24/// given registry.
25/// This can be used outside to create your own registry with the builtin types
26/// _and_ extra third party types.
27pub fn add_default_services(reg: &mut Registry) {
28 snix_castore::composition::add_default_services(reg);
29 crate::pathinfoservice::register_pathinfo_services(reg);
30}