#![allow(async_fn_in_trait)]
pub trait ContextError {
type Error;
}
pub trait Compressible {
type Compressed: Sized;
}
pub trait CompressibleBy<Ctx>: Compressible
where
Ctx: ContextError,
{
async fn compress_with(&self, ctx: &mut Ctx) -> Result<Self::Compressed, Ctx::Error>;
}
pub trait DecompressibleBy<Ctx>: Compressible
where
Ctx: ContextError,
Self: Sized,
{
async fn decompress_with(c: Self::Compressed, ctx: &Ctx) -> Result<Self, Ctx::Error>;
}
pub trait Decompress<Decompressed, Ctx>
where
Ctx: ContextError,
{
async fn decompress(self, ctx: &Ctx) -> Result<Decompressed, Ctx::Error>;
}
impl<T, Ctx, Decompressed> Decompress<Decompressed, Ctx> for T
where
Ctx: ContextError,
Decompressed: DecompressibleBy<Ctx, Compressed = Self>,
{
async fn decompress(self, ctx: &Ctx) -> Result<Decompressed, Ctx::Error> {
Decompressed::decompress_with(self, ctx).await
}
}