1
1
//! Delegate rpc calls
2
2
3
- use std:: sync:: Arc ;
4
3
use std:: collections:: HashMap ;
4
+ use std:: sync:: Arc ;
5
5
6
- use crate :: types:: { Params , Value , Error } ;
7
6
use crate :: calls:: { Metadata , RemoteProcedure , RpcMethod , RpcNotification } ;
8
- use futures :: IntoFuture ;
7
+ use crate :: types :: { Error , Params , Value } ;
9
8
use crate :: BoxFuture ;
9
+ use futures:: IntoFuture ;
10
10
11
11
struct DelegateAsyncMethod < T , F > {
12
12
delegate : Arc < T > ,
13
13
closure : F ,
14
14
}
15
15
16
- impl < T , M , F , I > RpcMethod < M > for DelegateAsyncMethod < T , F > where
16
+ impl < T , M , F , I > RpcMethod < M > for DelegateAsyncMethod < T , F >
17
+ where
17
18
M : Metadata ,
18
19
F : Fn ( & T , Params ) -> I ,
19
20
I : IntoFuture < Item = Value , Error = Error > ,
@@ -32,7 +33,8 @@ struct DelegateMethodWithMeta<T, F> {
32
33
closure : F ,
33
34
}
34
35
35
- impl < T , M , F , I > RpcMethod < M > for DelegateMethodWithMeta < T , F > where
36
+ impl < T , M , F , I > RpcMethod < M > for DelegateMethodWithMeta < T , F >
37
+ where
36
38
M : Metadata ,
37
39
F : Fn ( & T , Params , M ) -> I ,
38
40
I : IntoFuture < Item = Value , Error = Error > ,
@@ -51,7 +53,8 @@ struct DelegateNotification<T, F> {
51
53
closure : F ,
52
54
}
53
55
54
- impl < T , M , F > RpcNotification < M > for DelegateNotification < T , F > where
56
+ impl < T , M , F > RpcNotification < M > for DelegateNotification < T , F >
57
+ where
55
58
F : Fn ( & T , Params ) + ' static ,
56
59
F : Send + Sync + ' static ,
57
60
T : Send + Sync + ' static ,
@@ -64,15 +67,17 @@ impl<T, M, F> RpcNotification<M> for DelegateNotification<T, F> where
64
67
}
65
68
66
69
/// A set of RPC methods and notifications tied to single `delegate` struct.
67
- pub struct IoDelegate < T , M = ( ) > where
70
+ pub struct IoDelegate < T , M = ( ) >
71
+ where
68
72
T : Send + Sync + ' static ,
69
73
M : Metadata ,
70
74
{
71
75
delegate : Arc < T > ,
72
76
methods : HashMap < String , RemoteProcedure < M > > ,
73
77
}
74
78
75
- impl < T , M > IoDelegate < T , M > where
79
+ impl < T , M > IoDelegate < T , M >
80
+ where
76
81
T : Send + Sync + ' static ,
77
82
M : Metadata ,
78
83
{
@@ -91,50 +96,57 @@ impl<T, M> IoDelegate<T, M> where
91
96
}
92
97
93
98
/// Adds async method to the delegate.
94
- pub fn add_method < F , I > ( & mut self , name : & str , method : F ) where
99
+ pub fn add_method < F , I > ( & mut self , name : & str , method : F )
100
+ where
95
101
F : Fn ( & T , Params ) -> I ,
96
102
I : IntoFuture < Item = Value , Error = Error > ,
97
103
F : Send + Sync + ' static ,
98
104
I :: Future : Send + ' static ,
99
105
{
100
- self . methods . insert ( name. into ( ) , RemoteProcedure :: Method ( Arc :: new (
101
- DelegateAsyncMethod {
106
+ self . methods . insert (
107
+ name. into ( ) ,
108
+ RemoteProcedure :: Method ( Arc :: new ( DelegateAsyncMethod {
102
109
delegate : self . delegate . clone ( ) ,
103
110
closure : method,
104
- }
105
- ) ) ) ;
111
+ } ) ) ,
112
+ ) ;
106
113
}
107
114
108
115
/// Adds async method with metadata to the delegate.
109
- pub fn add_method_with_meta < F , I > ( & mut self , name : & str , method : F ) where
116
+ pub fn add_method_with_meta < F , I > ( & mut self , name : & str , method : F )
117
+ where
110
118
F : Fn ( & T , Params , M ) -> I ,
111
119
I : IntoFuture < Item = Value , Error = Error > ,
112
120
F : Send + Sync + ' static ,
113
121
I :: Future : Send + ' static ,
114
122
{
115
- self . methods . insert ( name. into ( ) , RemoteProcedure :: Method ( Arc :: new (
116
- DelegateMethodWithMeta {
123
+ self . methods . insert (
124
+ name. into ( ) ,
125
+ RemoteProcedure :: Method ( Arc :: new ( DelegateMethodWithMeta {
117
126
delegate : self . delegate . clone ( ) ,
118
127
closure : method,
119
- }
120
- ) ) ) ;
128
+ } ) ) ,
129
+ ) ;
121
130
}
122
131
123
132
/// Adds notification to the delegate.
124
- pub fn add_notification < F > ( & mut self , name : & str , notification : F ) where
133
+ pub fn add_notification < F > ( & mut self , name : & str , notification : F )
134
+ where
125
135
F : Fn ( & T , Params ) ,
126
136
F : Send + Sync + ' static ,
127
137
{
128
- self . methods . insert ( name. into ( ) , RemoteProcedure :: Notification ( Arc :: new (
129
- DelegateNotification {
138
+ self . methods . insert (
139
+ name. into ( ) ,
140
+ RemoteProcedure :: Notification ( Arc :: new ( DelegateNotification {
130
141
delegate : self . delegate . clone ( ) ,
131
142
closure : notification,
132
- }
133
- ) ) ) ;
143
+ } ) ) ,
144
+ ) ;
134
145
}
135
146
}
136
147
137
- impl < T , M > Into < HashMap < String , RemoteProcedure < M > > > for IoDelegate < T , M > where
148
+ impl < T , M > Into < HashMap < String , RemoteProcedure < M > > > for IoDelegate < T , M >
149
+ where
138
150
T : Send + Sync + ' static ,
139
151
M : Metadata ,
140
152
{
0 commit comments