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
use core::{
future::Future,
pin::Pin,
};
use super::{
linear_to_shared::LinearToShared,
shared_to_linear::SharedToLinear,
};
use crate::internal::base::*;
pub struct Lock<F>
where
F: SharedRecApp<SharedToLinear<LinearToShared<F>>>,
{
pub(crate) unlock: Receiver<(SenderOnce<()>, SenderOnce<LinearToShared<F>>)>,
}
impl<F> SealedProtocol for Lock<F> where
F: SharedRecApp<SharedToLinear<LinearToShared<F>>>
{
}
impl<F> Protocol for Lock<F>
where
F: Protocol,
F: SharedRecApp<SharedToLinear<LinearToShared<F>>>,
F::Applied: Protocol,
{
type ClientEndpoint = ReceiverOnce<Lock<F>>;
type ProviderEndpoint = SenderOnce<Lock<F>>;
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 payload = client_end.recv().await.unwrap();
provider_end.send(payload).unwrap();
})
}
}