diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml index 6bf4d076..5cceb0b7 100644 --- a/proxmox-notify/Cargo.toml +++ b/proxmox-notify/Cargo.toml @@ -11,6 +11,7 @@ exclude.workspace = true handlebars = { workspace = true } lazy_static.workspace = true log.workspace = true +once_cell.workspace = true openssl.workspace = true proxmox-http = { workspace = true, features = ["client-sync"], optional = true } proxmox-human-byte.workspace = true diff --git a/proxmox-notify/src/context.rs b/proxmox-notify/src/context.rs new file mode 100644 index 00000000..660b27fb --- /dev/null +++ b/proxmox-notify/src/context.rs @@ -0,0 +1,14 @@ +use once_cell::sync::OnceCell; +use std::fmt::Debug; + +pub trait Context: Send + Sync + Debug {} + +static CONTEXT: OnceCell<&'static dyn Context> = OnceCell::new(); + +pub fn set_context(context: &'static dyn Context) { + CONTEXT.set(context).expect("context has already been set"); +} + +pub(crate) fn context() -> &'static dyn Context { + *CONTEXT.get().expect("context has not been yet") +} diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs index e254604b..0059e44b 100644 --- a/proxmox-notify/src/lib.rs +++ b/proxmox-notify/src/lib.rs @@ -13,6 +13,7 @@ use std::error::Error as StdError; pub mod api; mod config; +pub mod context; pub mod endpoints; pub mod filter; pub mod group;