use crate::Context;
use core::convert::Infallible;
use super::{Buffered, Mount, Streaming, Worn};
use crate::{
Async, AsyncStreamOperator, Block, Declared, Delivery, Effect, Emitter, Feed, Fin, Operator,
StreamOperator, Unchanneled,
};
struct Buffer;
struct Windows;
struct AwaitedWindows;
impl Operator for Buffer {
type Error = Infallible;
type In = u8;
type Out = u8;
fn accept(
&mut self,
_ctx: &Context,
_delivery: Delivery<Self::In>,
_emitter: &mut Emitter<Self::Out>,
) -> Result<(), Self::Error> {
Ok(())
}
}
impl StreamOperator for Windows {
type Error = Infallible;
type In = u8;
type Out = u8;
fn run(
&mut self,
_ctx: &Context,
_delivery: Delivery<Self::In>,
_feed: Feed<Self::Out>,
) -> Result<Fin, Self::Error> {
Ok(Fin::Spent)
}
}
impl AsyncStreamOperator for AwaitedWindows {
type Error = Infallible;
type In = u8;
type Out = u8;
async fn run(
&mut self,
_ctx: &Context,
_delivery: Delivery<Self::In>,
_feed: Feed<Self::Out>,
) -> Result<Fin, Self::Error> {
Ok(Fin::Spent)
}
}
impl Declared for Buffer {
const EFFECT: Effect = Effect::Pure;
type Channels = Unchanneled;
type Mode = Block;
type Options = ();
type Pair = Buffered;
type Wires<O> = crate::Downstream<O>;
type Attribution<O> = ();
}
impl Declared for Windows {
const EFFECT: Effect = Effect::Pure;
type Channels = Unchanneled;
type Mode = Block;
type Options = ();
type Pair = Streaming;
type Wires<O> = crate::Downstream<O>;
type Attribution<O> = ();
}
impl Declared for AwaitedWindows {
const EFFECT: Effect = Effect::Pure;
type Channels = Unchanneled;
type Mode = Async;
type Options = ();
type Pair = Streaming;
type Wires<O> = crate::Downstream<O>;
type Attribution<O> = ();
}
#[test]
fn the_seats_name_the_cell_their_declaration_selected() {
fn same<T>(_: T, _: T) {}
same(
Worn::<<Buffer as Declared>::Pair, <Buffer as Declared>::Mode>::default(),
Worn::<Buffered, Block>::default(),
);
same(
Worn::<<Windows as Declared>::Pair, <Windows as Declared>::Mode>::default(),
Worn::<Streaming, Block>::default(),
);
same(
Worn::<<AwaitedWindows as Declared>::Pair, <AwaitedWindows as Declared>::Mode>::default(),
Worn::<Streaming, Async>::default(),
);
}
#[test]
fn a_cell_projects_the_messages_of_the_pair_it_names() {
fn takes<C, N>(_: <C as Mount<N>>::In) -> <C as Mount<N>>::Out
where
N: Declared,
C: Mount<N>,
<C as Mount<N>>::In: Into<<C as Mount<N>>::Out>,
{
unreachable!("the signature is the assertion")
}
let _ = takes::<Worn<Buffered, Block>, Buffer>;
let _ = takes::<Worn<Streaming, Block>, Windows>;
let _ = takes::<Worn<Streaming, Async>, AwaitedWindows>;
}
#[test]
fn the_fold_reads_a_syncness_from_either_pair() {
const {
assert!(<Worn<Buffered, Block> as Mount<Buffer>>::SYNC);
assert!(<Worn<Streaming, Block> as Mount<Windows>>::SYNC);
assert!(!<Worn<Streaming, Async> as Mount<AwaitedWindows>>::SYNC);
};
}