Skip to main content

ferrite_session/internal/protocol/value/
send.rs

1use core::{
2  future::Future,
3  marker::PhantomData,
4  pin::Pin,
5};
6
7use crate::internal::base::*;
8
9pub struct SendValue<T, A>(PhantomData<(T, A)>);
10
11impl<T, A> SealedProtocol for SendValue<T, A> {}
12
13impl<T, A> Protocol for SendValue<T, A>
14where
15  T: Send + 'static,
16  A: Protocol,
17{
18  type ClientEndpoint = ReceiverOnce<(Value<T>, A::ClientEndpoint)>;
19  type ProviderEndpoint = SenderOnce<(Value<T>, A::ClientEndpoint)>;
20
21  fn create_endpoints() -> (Self::ProviderEndpoint, Self::ClientEndpoint)
22  {
23    once_channel()
24  }
25
26  fn forward(
27    client_end: Self::ClientEndpoint,
28    provider_end: Self::ProviderEndpoint,
29  ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>
30  {
31    Box::pin(async {
32      let payload = client_end.recv().await.unwrap();
33      provider_end.send(payload).unwrap();
34    })
35  }
36}
37
38impl<X, T, A> RecApp<X> for SendValue<T, A>
39where
40  T: Send + 'static,
41  A: RecApp<X>,
42{
43  type Applied = SendValue<T, A::Applied>;
44}
45
46impl<T, A, X> SharedRecApp<X> for SendValue<T, A>
47where
48  T: Send + 'static,
49  A: SharedRecApp<X>,
50{
51  type Applied = SendValue<T, A::Applied>;
52}