@@ -5,7 +5,8 @@ use std::time::Duration;
5
5
use crate :: mqttbytes:: { v4:: * , QoS } ;
6
6
use crate :: tokens:: { NoResponse , Resolver , Token } ;
7
7
use crate :: {
8
- valid_filter, valid_topic, ConnectionError , Event , EventLoop , MqttOptions , Pkid , Request ,
8
+ valid_filter, valid_topic, AckOfAck , AckOfPub , ConnectionError , Event , EventLoop , MqttOptions ,
9
+ Request ,
9
10
} ;
10
11
11
12
use bytes:: Bytes ;
@@ -75,7 +76,7 @@ impl AsyncClient {
75
76
qos : QoS ,
76
77
retain : bool ,
77
78
payload : V ,
78
- ) -> Result < Token < Pkid > , ClientError >
79
+ ) -> Result < Token < AckOfPub > , ClientError >
79
80
where
80
81
S : Into < String > ,
81
82
V : Into < Vec < u8 > > ,
@@ -100,7 +101,7 @@ impl AsyncClient {
100
101
qos : QoS ,
101
102
retain : bool ,
102
103
payload : V ,
103
- ) -> Result < Token < Pkid > , ClientError >
104
+ ) -> Result < Token < AckOfPub > , ClientError >
104
105
where
105
106
S : Into < String > ,
106
107
V : Into < Vec < u8 > > ,
@@ -119,7 +120,7 @@ impl AsyncClient {
119
120
}
120
121
121
122
/// Sends a MQTT PubAck to the `EventLoop`. Only needed in if `manual_acks` flag is set.
122
- pub async fn ack ( & self , publish : & Publish ) -> Result < Token < NoResponse > , ClientError > {
123
+ pub async fn ack ( & self , publish : & Publish ) -> Result < Token < AckOfAck > , ClientError > {
123
124
let ( resolver, token) = Resolver :: new ( ) ;
124
125
let ack = get_ack_req ( publish, resolver) ;
125
126
if let Some ( ack) = ack {
@@ -130,7 +131,7 @@ impl AsyncClient {
130
131
}
131
132
132
133
/// Attempts to send a MQTT PubAck to the `EventLoop`. Only needed in if `manual_acks` flag is set.
133
- pub fn try_ack ( & self , publish : & Publish ) -> Result < Token < NoResponse > , ClientError > {
134
+ pub fn try_ack ( & self , publish : & Publish ) -> Result < Token < AckOfAck > , ClientError > {
134
135
let ( resolver, token) = Resolver :: new ( ) ;
135
136
let ack = get_ack_req ( publish, resolver) ;
136
137
if let Some ( ack) = ack {
@@ -147,7 +148,7 @@ impl AsyncClient {
147
148
qos : QoS ,
148
149
retain : bool ,
149
150
payload : Bytes ,
150
- ) -> Result < Token < Pkid > , ClientError >
151
+ ) -> Result < Token < AckOfPub > , ClientError >
151
152
where
152
153
S : Into < String > ,
153
154
{
@@ -165,7 +166,7 @@ impl AsyncClient {
165
166
& self ,
166
167
topic : S ,
167
168
qos : QoS ,
168
- ) -> Result < Token < Pkid > , ClientError > {
169
+ ) -> Result < Token < SubAck > , ClientError > {
169
170
let ( resolver, token) = Resolver :: new ( ) ;
170
171
let subscribe = Subscribe :: new ( topic, qos) ;
171
172
@@ -184,7 +185,7 @@ impl AsyncClient {
184
185
& self ,
185
186
topic : S ,
186
187
qos : QoS ,
187
- ) -> Result < Token < Pkid > , ClientError > {
188
+ ) -> Result < Token < SubAck > , ClientError > {
188
189
let ( resolver, token) = Resolver :: new ( ) ;
189
190
let subscribe = Subscribe :: new ( topic, qos) ;
190
191
let is_valid = subscribe_has_valid_filters ( & subscribe) ;
@@ -198,7 +199,7 @@ impl AsyncClient {
198
199
}
199
200
200
201
/// Sends a MQTT Subscribe for multiple topics to the `EventLoop`
201
- pub async fn subscribe_many < T > ( & self , topics : T ) -> Result < Token < Pkid > , ClientError >
202
+ pub async fn subscribe_many < T > ( & self , topics : T ) -> Result < Token < SubAck > , ClientError >
202
203
where
203
204
T : IntoIterator < Item = SubscribeFilter > ,
204
205
{
@@ -216,7 +217,7 @@ impl AsyncClient {
216
217
}
217
218
218
219
/// Attempts to send a MQTT Subscribe for multiple topics to the `EventLoop`
219
- pub fn try_subscribe_many < T > ( & self , topics : T ) -> Result < Token < Pkid > , ClientError >
220
+ pub fn try_subscribe_many < T > ( & self , topics : T ) -> Result < Token < SubAck > , ClientError >
220
221
where
221
222
T : IntoIterator < Item = SubscribeFilter > ,
222
223
{
@@ -233,7 +234,10 @@ impl AsyncClient {
233
234
}
234
235
235
236
/// Sends a MQTT Unsubscribe to the `EventLoop`
236
- pub async fn unsubscribe < S : Into < String > > ( & self , topic : S ) -> Result < Token < Pkid > , ClientError > {
237
+ pub async fn unsubscribe < S : Into < String > > (
238
+ & self ,
239
+ topic : S ,
240
+ ) -> Result < Token < UnsubAck > , ClientError > {
237
241
let ( resolver, token) = Resolver :: new ( ) ;
238
242
let unsubscribe = Unsubscribe :: new ( topic. into ( ) ) ;
239
243
let request = Request :: Unsubscribe ( unsubscribe, resolver) ;
@@ -243,7 +247,10 @@ impl AsyncClient {
243
247
}
244
248
245
249
/// Attempts to send a MQTT Unsubscribe to the `EventLoop`
246
- pub fn try_unsubscribe < S : Into < String > > ( & self , topic : S ) -> Result < Token < Pkid > , ClientError > {
250
+ pub fn try_unsubscribe < S : Into < String > > (
251
+ & self ,
252
+ topic : S ,
253
+ ) -> Result < Token < UnsubAck > , ClientError > {
247
254
let ( resolver, token) = Resolver :: new ( ) ;
248
255
let unsubscribe = Unsubscribe :: new ( topic. into ( ) ) ;
249
256
let request = Request :: Unsubscribe ( unsubscribe, resolver) ;
@@ -271,10 +278,10 @@ impl AsyncClient {
271
278
}
272
279
}
273
280
274
- fn get_ack_req ( publish : & Publish , resolver : Resolver < ( ) > ) -> Option < Request > {
281
+ fn get_ack_req ( publish : & Publish , resolver : Resolver < AckOfAck > ) -> Option < Request > {
275
282
let ack = match publish. qos {
276
283
QoS :: AtMostOnce => {
277
- resolver. resolve ( ( ) ) ;
284
+ resolver. resolve ( AckOfAck :: None ) ;
278
285
return None ;
279
286
}
280
287
QoS :: AtLeastOnce => Request :: PubAck ( PubAck :: new ( publish. pkid ) , resolver) ,
@@ -331,7 +338,7 @@ impl Client {
331
338
qos : QoS ,
332
339
retain : bool ,
333
340
payload : V ,
334
- ) -> Result < Token < Pkid > , ClientError >
341
+ ) -> Result < Token < AckOfPub > , ClientError >
335
342
where
336
343
S : Into < String > ,
337
344
V : Into < Vec < u8 > > ,
@@ -355,7 +362,7 @@ impl Client {
355
362
qos : QoS ,
356
363
retain : bool ,
357
364
payload : V ,
358
- ) -> Result < Token < Pkid > , ClientError >
365
+ ) -> Result < Token < AckOfPub > , ClientError >
359
366
where
360
367
S : Into < String > ,
361
368
V : Into < Vec < u8 > > ,
@@ -364,7 +371,7 @@ impl Client {
364
371
}
365
372
366
373
/// Sends a MQTT PubAck to the `EventLoop`. Only needed in if `manual_acks` flag is set.
367
- pub fn ack ( & self , publish : & Publish ) -> Result < Token < NoResponse > , ClientError > {
374
+ pub fn ack ( & self , publish : & Publish ) -> Result < Token < AckOfAck > , ClientError > {
368
375
let ( resolver, token) = Resolver :: new ( ) ;
369
376
let ack = get_ack_req ( publish, resolver) ;
370
377
if let Some ( ack) = ack {
@@ -375,7 +382,7 @@ impl Client {
375
382
}
376
383
377
384
/// Sends a MQTT PubAck to the `EventLoop`. Only needed in if `manual_acks` flag is set.
378
- pub fn try_ack ( & self , publish : & Publish ) -> Result < Token < NoResponse > , ClientError > {
385
+ pub fn try_ack ( & self , publish : & Publish ) -> Result < Token < AckOfAck > , ClientError > {
379
386
self . client . try_ack ( publish)
380
387
}
381
388
@@ -384,7 +391,7 @@ impl Client {
384
391
& self ,
385
392
topic : S ,
386
393
qos : QoS ,
387
- ) -> Result < Token < Pkid > , ClientError > {
394
+ ) -> Result < Token < SubAck > , ClientError > {
388
395
let ( resolver, token) = Resolver :: new ( ) ;
389
396
let subscribe = Subscribe :: new ( topic, qos) ;
390
397
let is_valid = subscribe_has_valid_filters ( & subscribe) ;
@@ -402,12 +409,12 @@ impl Client {
402
409
& self ,
403
410
topic : S ,
404
411
qos : QoS ,
405
- ) -> Result < Token < Pkid > , ClientError > {
412
+ ) -> Result < Token < SubAck > , ClientError > {
406
413
self . client . try_subscribe ( topic, qos)
407
414
}
408
415
409
416
/// Sends a MQTT Subscribe for multiple topics to the `EventLoop`
410
- pub fn subscribe_many < T > ( & self , topics : T ) -> Result < Token < Pkid > , ClientError >
417
+ pub fn subscribe_many < T > ( & self , topics : T ) -> Result < Token < SubAck > , ClientError >
411
418
where
412
419
T : IntoIterator < Item = SubscribeFilter > ,
413
420
{
@@ -424,15 +431,15 @@ impl Client {
424
431
Ok ( token)
425
432
}
426
433
427
- pub fn try_subscribe_many < T > ( & self , topics : T ) -> Result < Token < Pkid > , ClientError >
434
+ pub fn try_subscribe_many < T > ( & self , topics : T ) -> Result < Token < SubAck > , ClientError >
428
435
where
429
436
T : IntoIterator < Item = SubscribeFilter > ,
430
437
{
431
438
self . client . try_subscribe_many ( topics)
432
439
}
433
440
434
441
/// Sends a MQTT Unsubscribe to the `EventLoop`
435
- pub fn unsubscribe < S : Into < String > > ( & self , topic : S ) -> Result < Token < Pkid > , ClientError > {
442
+ pub fn unsubscribe < S : Into < String > > ( & self , topic : S ) -> Result < Token < UnsubAck > , ClientError > {
436
443
let ( resolver, token) = Resolver :: new ( ) ;
437
444
let unsubscribe = Unsubscribe :: new ( topic. into ( ) ) ;
438
445
let request = Request :: Unsubscribe ( unsubscribe, resolver) ;
@@ -442,7 +449,10 @@ impl Client {
442
449
}
443
450
444
451
/// Sends a MQTT Unsubscribe to the `EventLoop`
445
- pub fn try_unsubscribe < S : Into < String > > ( & self , topic : S ) -> Result < Token < Pkid > , ClientError > {
452
+ pub fn try_unsubscribe < S : Into < String > > (
453
+ & self ,
454
+ topic : S ,
455
+ ) -> Result < Token < UnsubAck > , ClientError > {
446
456
self . client . try_unsubscribe ( topic)
447
457
}
448
458
0 commit comments