1#[macro_export]
2macro_rules! managed {
3 ($type:ident) => {
4 static _MANAGED_ROOT_PATH: std::sync::OnceLock<std::path::PathBuf> = std::sync::OnceLock::new();
5 static _STORAGE: refs::main_lock::MainLock<refs::manage::DataStorage<$type>> =
6 refs::main_lock::MainLock::new();
7
8 impl refs::manage::Managed for $type {}
9
10 impl refs::manage::DataManager<$type> for $type {
11 fn root_path() -> &'static std::path::Path {
12 _MANAGED_ROOT_PATH.get().expect(&format!(
13 "Managed root path for type {} is not set.",
14 stringify!($type)
15 ))
16 }
17
18 fn set_root_path(path: impl Into<std::path::PathBuf>) {
19 let path = path.into();
20 _MANAGED_ROOT_PATH.set(path.to_path_buf()).expect(&format!(
21 "Managed root path for type {} was already set set.",
22 stringify!($type)
23 ))
24 }
25
26 fn storage() -> &'static mut refs::manage::DataStorage<$type> {
27 _STORAGE.get_mut()
28 }
29 }
30 };
31}