use std::fmt;
pub trait MakeLayerError: sealed::Sealed + Send + Sync + 'static {
type Error;
fn make_layer_error(&self) -> Self::Error;
}
pub struct LayerErrorFn<F>(F);
impl<F, E> LayerErrorFn<F>
where
F: FnOnce() -> E + Clone + Send + Sync + 'static,
E: Send + 'static,
{
pub(crate) const fn new(f: F) -> Self {
Self(f)
}
}
impl<F> fmt::Debug for LayerErrorFn<F>
where
F: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("LayerErrorFn").field(&self.0).finish()
}
}
impl<F> Clone for LayerErrorFn<F>
where
F: Clone,
{
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<F, E> MakeLayerError for LayerErrorFn<F>
where
F: FnOnce() -> E + Clone + Send + Sync + 'static,
E: Send + 'static,
{
type Error = E;
fn make_layer_error(&self) -> Self::Error {
self.0.clone()()
}
}
pub struct LayerErrorStatic<E>(E);
impl<E> fmt::Debug for LayerErrorStatic<E>
where
E: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("LayerErrorStatic").field(&self.0).finish()
}
}
impl<E> Clone for LayerErrorStatic<E>
where
E: Clone,
{
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<E> LayerErrorStatic<E>
where
E: Clone + Send + Sync + 'static,
{
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> {}
}