use std::sync::Arc;
use async_trait::async_trait;
use super::{context::BackendContext, AnyResult};
#[async_trait]
pub trait CheckUp: Send + Sync {
async fn check_up(&self) -> AnyResult<()> {
Ok(())
}
}
pub type BackendFeature<C, F> = Arc<dyn Fn(&C) -> Option<Box<F>> + Send + Sync>;
#[derive(Default)]
pub enum BackendFeatureSource<C: BackendContext, F: ?Sized> {
None,
#[default]
Context,
Backend(BackendFeature<C, F>),
}
impl<C, F> Clone for BackendFeatureSource<C, F>
where
C: BackendContext,
F: ?Sized,
{
fn clone(&self) -> Self {
match self {
Self::None => Self::None,
Self::Context => Self::Context,
Self::Backend(f) => Self::Backend(f.clone()),
}
}
}
impl<C, F, T> From<T> for BackendFeatureSource<C, F>
where
C: BackendContext,
F: ?Sized,
T: Fn(&C) -> Option<Box<F>> + Send + Sync + 'static,
{
fn from(value: T) -> Self {
Self::Backend(Arc::new(value))
}
}