1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use core::{
future::Future,
marker::PhantomData,
pin::Pin,
};
use crate::internal::{
base::*,
functional::*,
};
pub struct InternalChoice<Row>(PhantomData<Row>);
impl<Row1> SealedProtocol for InternalChoice<Row1> {}
impl<Row> Protocol for InternalChoice<Row>
where
Row: ToRow + Send + 'static,
{
type ClientEndpoint =
ReceiverOnce<AppSum<'static, Row::Row, ClientEndpointF>>;
type ProviderEndpoint =
SenderOnce<AppSum<'static, Row::Row, ClientEndpointF>>;
fn create_endpoints() -> (Self::ProviderEndpoint, Self::ClientEndpoint)
{
once_channel()
}
fn forward(
client_end: Self::ClientEndpoint,
provider_end: Self::ProviderEndpoint,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>
{
Box::pin(async {
let endpoint = client_end.recv().await.unwrap();
provider_end.send(endpoint).unwrap();
})
}
}
impl<Row1, Row2, Row3, A> RecApp<A> for InternalChoice<Row1>
where
A: Send + 'static,
Row1: Send + 'static,
Row1: ToRow<Row = Row2>,
Row2: RowCon,
Row2: RecApp<A, Applied = Row3>,
Row3: RowCon,
{
type Applied = InternalChoice<RecRow<A, Row1>>;
}
impl<Row1, Row2, Row3, A> SharedRecApp<A> for InternalChoice<Row1>
where
A: Send + 'static,
Row1: ToRow<Row = Row2>,
Row2: RowCon,
Row2: SharedRecApp<A, Applied = Row3>,
Row3: RowCon,
{
type Applied = InternalChoice<SharedRecRow<A, Row1>>;
}