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