1
1
use serde:: { Deserialize , Deserializer , Serialize } ;
2
- use std:: { marker :: PhantomData , time:: Duration } ;
2
+ use std:: time:: Duration ;
3
3
use time:: OffsetDateTime ;
4
4
5
5
use crate :: {
@@ -400,10 +400,17 @@ impl AsRef<u32> for Task {
400
400
}
401
401
402
402
#[ derive( Debug , Serialize , Clone ) ]
403
- pub enum TasksPagination { }
403
+ pub struct TasksPagination {
404
+ // Maximum number of tasks to return
405
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
406
+ limit : Option < u32 > ,
407
+ // The first task uid that should be returned
408
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
409
+ from : Option < u32 > ,
410
+ }
404
411
405
412
#[ derive( Debug , Serialize , Clone ) ]
406
- pub enum TasksDefault { }
413
+ pub struct TasksDefault { }
407
414
408
415
pub type TasksSearchQuery < ' a > = TasksQuery < ' a , TasksPagination > ;
409
416
pub type TasksCancelQuery < ' a > = TasksQuery < ' a , TasksDefault > ;
@@ -461,14 +468,9 @@ pub struct TasksQuery<'a, T> {
461
468
serialize_with = "time::serde::rfc3339::option::serialize"
462
469
) ]
463
470
after_finished_at : Option < OffsetDateTime > ,
464
- // Maximum number of tasks to return
465
- #[ serde( skip_serializing_if = "Option::is_none" ) ]
466
- limit : Option < u32 > ,
467
- // The first task uid that should be returned
468
- #[ serde( skip_serializing_if = "Option::is_none" ) ]
469
- from : Option < u32 > ,
470
- #[ serde( skip_serializing) ]
471
- phantom_data : PhantomData < T > ,
471
+
472
+ #[ serde( flatten) ]
473
+ pagination : T ,
472
474
}
473
475
474
476
#[ allow( missing_docs) ]
@@ -543,10 +545,6 @@ impl<'a, T> TasksQuery<'a, T> {
543
545
self . after_finished_at = Some ( * after_finished_at) ;
544
546
self
545
547
}
546
-
547
- pub async fn execute ( & ' a self ) -> Result < TasksResults , Error > {
548
- self . client . get_tasks_with ( self ) . await
549
- }
550
548
}
551
549
552
550
impl < ' a > TasksQuery < ' a , TasksDefault > {
@@ -556,18 +554,20 @@ impl<'a> TasksQuery<'a, TasksDefault> {
556
554
index_uid : None ,
557
555
status : None ,
558
556
task_type : None ,
559
- limit : None ,
560
- from : None ,
561
557
uid : None ,
562
558
before_enqueued_at : None ,
563
559
after_enqueued_at : None ,
564
560
before_started_at : None ,
565
561
after_started_at : None ,
566
562
before_finished_at : None ,
567
563
after_finished_at : None ,
568
- phantom_data : PhantomData ,
564
+ pagination : TasksDefault { } ,
569
565
}
570
566
}
567
+
568
+ // pub async fn execute(&'a self) -> Result<TasksResults, Error> {
569
+ // self.client.get_tasks_with(self).await
570
+ // }
571
571
}
572
572
573
573
impl < ' a > TasksQuery < ' a , TasksPagination > {
@@ -577,26 +577,30 @@ impl<'a> TasksQuery<'a, TasksPagination> {
577
577
index_uid : None ,
578
578
status : None ,
579
579
task_type : None ,
580
- limit : None ,
581
- from : None ,
582
580
uid : None ,
583
581
before_enqueued_at : None ,
584
582
after_enqueued_at : None ,
585
583
before_started_at : None ,
586
584
after_started_at : None ,
587
585
before_finished_at : None ,
588
586
after_finished_at : None ,
589
- phantom_data : PhantomData ,
587
+ pagination : TasksPagination {
588
+ limit : None ,
589
+ from : None ,
590
+ } ,
590
591
}
591
592
}
592
593
pub fn with_limit < ' b > ( & ' b mut self , limit : u32 ) -> & ' b mut TasksQuery < ' a , TasksPagination > {
593
- self . limit = Some ( limit) ;
594
+ self . pagination . limit = Some ( limit) ;
594
595
self
595
596
}
596
597
pub fn with_from < ' b > ( & ' b mut self , from : u32 ) -> & ' b mut TasksQuery < ' a , TasksPagination > {
597
- self . from = Some ( from) ;
598
+ self . pagination . from = Some ( from) ;
598
599
self
599
600
}
601
+ pub async fn execute ( & ' a self ) -> Result < TasksResults , Error > {
602
+ self . client . get_tasks_with ( self ) . await
603
+ }
600
604
}
601
605
602
606
#[ cfg( test) ]
0 commit comments