pub trait MakeLayerError: sealed::Sealed + Send + Sync + 'static {
type Error;
fn make_layer_error(&self) -> Self::Error;
}
#[derive(Debug, Clone)]
pub struct LayerErrorFn<F>(F);
impl<F, E> LayerErrorFn<F>
where
F: Fn() -> E + Send + Sync + 'static,
E: Send + 'static,
{
#[cfg(feature = "std")]
pub(crate) const fn new(f: F) -> Self {
Self(f)
}
}
impl<F, E> MakeLayerError for LayerErrorFn<F>
where
F: Fn() -> E + Send + Sync + 'static,
E: Send + 'static,
{
type Error = E;
fn make_layer_error(&self) -> Self::Error {
self.0()
}
}
#[derive(Debug, Clone)]
pub struct LayerErrorStatic<E>(E);
impl<E> LayerErrorStatic<E>
where
E: Clone + Send + Sync + 'static,
{
#[cfg(feature = "std")]
pub(crate) const fn new(e: E) -> Self {
Self(e)
}
}
impl<E> MakeLayerError for LayerErrorStatic<E>
where
E: Clone + Send + Sync + 'static,
{
type Error = E;
fn make_layer_error(&self) -> Self::Error {
self.0.clone()
}
}
mod sealed {
pub trait Sealed {}
impl<F> Sealed for super::LayerErrorFn<F> {}
impl<E> Sealed for super::LayerErrorStatic<E> {}
}