hermes_async_runtime_components/channel_once/
traits.rs1use cgp::prelude::*;
2use futures_channel::oneshot::{Receiver, Sender};
3use hermes_runtime_components::traits::channel_once::{
4 ChannelOnceTypeComponent, HasChannelOnceTypes, ProvideChannelOnceType,
5};
6
7pub trait HasOneShotChannelType: HasChannelOnceTypes {
8 fn from_oneshot_sender<T>(sender: Sender<T>) -> Self::SenderOnce<T>
9 where
10 T: Async;
11
12 fn from_oneshot_receiver<T>(receiver: Receiver<T>) -> Self::ReceiverOnce<T>
13 where
14 T: Async;
15
16 fn to_oneshot_sender<T>(sender: Self::SenderOnce<T>) -> Sender<T>
17 where
18 T: Async;
19
20 fn to_oneshot_receiver<T>(receiver: Self::ReceiverOnce<T>) -> Receiver<T>
21 where
22 T: Async;
23}
24
25pub trait OneShotChannelTypeProvider<Runtime>: ProvideChannelOnceType<Runtime> {
26 fn from_oneshot_sender<T>(sender: Sender<T>) -> Self::SenderOnce<T>
27 where
28 T: Async;
29
30 fn from_oneshot_receiver<T>(receiver: Receiver<T>) -> Self::ReceiverOnce<T>
31 where
32 T: Async;
33
34 fn to_oneshot_sender<T>(sender: Self::SenderOnce<T>) -> Sender<T>
35 where
36 T: Async;
37
38 fn to_oneshot_receiver<T>(receiver: Self::ReceiverOnce<T>) -> Receiver<T>
39 where
40 T: Async;
41}
42
43impl<Runtime, Components> HasOneShotChannelType for Runtime
44where
45 Runtime: HasComponents<Components = Components>,
46 Components: OneShotChannelTypeProvider<Runtime>,
47{
48 fn from_oneshot_sender<T>(sender: Sender<T>) -> Self::SenderOnce<T>
49 where
50 T: Async,
51 {
52 Components::from_oneshot_sender(sender)
53 }
54
55 fn from_oneshot_receiver<T>(receiver: Receiver<T>) -> Self::ReceiverOnce<T>
56 where
57 T: Async,
58 {
59 Components::from_oneshot_receiver(receiver)
60 }
61
62 fn to_oneshot_sender<T>(sender: Self::SenderOnce<T>) -> Sender<T>
63 where
64 T: Async,
65 {
66 Components::to_oneshot_sender(sender)
67 }
68
69 fn to_oneshot_receiver<T>(receiver: Self::ReceiverOnce<T>) -> Receiver<T>
70 where
71 T: Async,
72 {
73 Components::to_oneshot_receiver(receiver)
74 }
75}
76
77impl<Runtime, Component, Delegate> OneShotChannelTypeProvider<Runtime> for Component
78where
79 Component: DelegateComponent<ChannelOnceTypeComponent, Delegate = Delegate>,
80 Delegate: OneShotChannelTypeProvider<Runtime>,
81{
82 fn from_oneshot_sender<T>(sender: Sender<T>) -> Self::SenderOnce<T>
83 where
84 T: Async,
85 {
86 Delegate::from_oneshot_sender(sender)
87 }
88
89 fn from_oneshot_receiver<T>(receiver: Receiver<T>) -> Self::ReceiverOnce<T>
90 where
91 T: Async,
92 {
93 Delegate::from_oneshot_receiver(receiver)
94 }
95
96 fn to_oneshot_sender<T>(sender: Self::SenderOnce<T>) -> Sender<T>
97 where
98 T: Async,
99 {
100 Delegate::to_oneshot_sender(sender)
101 }
102
103 fn to_oneshot_receiver<T>(receiver: Self::ReceiverOnce<T>) -> Receiver<T>
104 where
105 T: Async,
106 {
107 Delegate::to_oneshot_receiver(receiver)
108 }
109}