use core::future::Future;
use std::sync::Arc;
pub trait AlgebraCall<Operation, Reply> {
fn ask(&self, operation: Operation) -> impl Future<Output = Option<Reply>> + Send;
}
pub trait AlgebraSend<Operation> {
#[must_use = "a feed whose reader is gone states nothing, and only the caller knows what that means"]
fn send(&self, operation: Operation) -> impl Future<Output = Option<()>> + Send;
}
impl<Operation, Reply, Calling> AlgebraCall<Operation, Reply> for &Calling
where
Calling: AlgebraCall<Operation, Reply> + ?Sized,
{
fn ask(&self, operation: Operation) -> impl Future<Output = Option<Reply>> + Send {
(**self).ask(operation)
}
}
impl<Operation, Reply, Calling> AlgebraCall<Operation, Reply> for Arc<Calling>
where
Calling: AlgebraCall<Operation, Reply> + ?Sized,
{
fn ask(&self, operation: Operation) -> impl Future<Output = Option<Reply>> + Send {
(**self).ask(operation)
}
}
impl<Operation, Sending> AlgebraSend<Operation> for &Sending
where
Sending: AlgebraSend<Operation> + ?Sized,
{
fn send(&self, operation: Operation) -> impl Future<Output = Option<()>> + Send {
(**self).send(operation)
}
}
impl<Operation, Sending> AlgebraSend<Operation> for Arc<Sending>
where
Sending: AlgebraSend<Operation> + ?Sized,
{
fn send(&self, operation: Operation) -> impl Future<Output = Option<()>> + Send {
(**self).send(operation)
}
}