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:
parent
97dac11823
commit
d6c1f181d6
@ -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
|
||||
|
14
proxmox-notify/src/context.rs
Normal file
14
proxmox-notify/src/context.rs
Normal 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")
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user