Skip to main content

ferrite_session/internal/protocol/shared/
linear_to_shared.rs

1use super::shared_to_linear::SharedToLinear;
2use crate::internal::base::*;
3
4pub trait HasSharedRecApp<F, A>: Send + 'static
5{
6  fn get_applied(self: Box<Self>) -> <F::Applied as Protocol>::ClientEndpoint
7  where
8    F: SharedRecApp<A>,
9    F::Applied: Protocol;
10}
11
12impl<F, A, FA, E> HasSharedRecApp<F, A> for E
13where
14  F: 'static,
15  A: 'static,
16  E: Send + 'static,
17  FA: Protocol<ClientEndpoint = E>,
18  F: SharedRecApp<A, Applied = FA>,
19{
20  fn get_applied(self: Box<Self>) -> <F::Applied as Protocol>::ClientEndpoint
21  {
22    *self
23  }
24}
25
26pub struct LinearToShared<F>
27{
28  pub(crate) linear:
29    Box<dyn HasSharedRecApp<F, SharedToLinear<LinearToShared<F>>>>,
30}
31
32impl<F> SealedSharedProtocol for LinearToShared<F> {}
33
34impl<F> SharedProtocol for LinearToShared<F>
35where
36  F: Protocol,
37  F: SharedRecApp<SharedToLinear<LinearToShared<F>>>,
38  F::Applied: Protocol,
39{
40}
41
42impl<F, T, E> ForwardChannel for LinearToShared<F>
43where
44  F: SharedRecApp<SharedToLinear<LinearToShared<F>>, Applied = T>,
45  F: Send + 'static,
46  T: Protocol<ClientEndpoint = E>,
47  E: ForwardChannel,
48{
49  fn forward_to(
50    self,
51    sender: OpaqueSender,
52    receiver: OpaqueReceiver,
53  )
54  {
55    self.linear.get_applied().forward_to(sender, receiver)
56  }
57
58  fn forward_from(
59    sender: OpaqueSender,
60    receiver: OpaqueReceiver,
61  ) -> Self
62  {
63    LinearToShared {
64      linear: Box::new(E::forward_from(sender, receiver)),
65    }
66  }
67}