notify: add context

Since `proxmox-notify` is intended to be used by multiple products,
there needs to be a way to inject product-specific behavior.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
Lukas Wagner 2023-07-20 16:31:44 +02:00 committed by Wolfgang Bumiller
parent 97dac11823
commit d6c1f181d6
3 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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")
}

View File

@ -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;