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;
}
pub trait AlgebraCarrier {
type Operation;
type Reply;
}
impl<Carrying> AlgebraCarrier for &Carrying
where
Carrying: AlgebraCarrier + ?Sized,
{
type Operation = Carrying::Operation;
type Reply = Carrying::Reply;
}
impl<Carrying> AlgebraCarrier for Arc<Carrying>
where
Carrying: AlgebraCarrier + ?Sized,
{
type Operation = Carrying::Operation;
type Reply = Carrying::Reply;
}
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)
}
}