@@ -21,7 +21,7 @@ pub struct UnpagedSearch<E, R> {
21
21
22
22
impl < E , R > UnpagedSearch < E , R >
23
23
where
24
- E : SearchExecutor < R > + ' static ,
24
+ E : UnpagedSearchExecutor < R > ,
25
25
{
26
26
pub fn new ( executor : E ) -> Self {
27
27
Self { executor, params : SearchParameters :: empty ( ) , resource_type : PhantomData }
@@ -65,18 +65,21 @@ where
65
65
self . with_raw ( key, value)
66
66
}
67
67
68
- /// Make this a paged search. Next pages can be fetched using
69
- /// [SearchResponse::next_page].
68
+ /// Execute the search
69
+ pub async fn send ( self ) -> Result < E :: Stream , Error > {
70
+ self . executor . search_unpaged ( self . params ) . await
71
+ }
72
+ }
73
+
74
+ impl < E , R > UnpagedSearch < E , R >
75
+ where
76
+ E : UnpagedSearchExecutor < R > + PagedSearchExecutor < R > ,
77
+ {
70
78
pub fn paged ( self , page_size : Option < u32 > ) -> PagedSearch < E , R > {
71
79
let Self { executor, params, resource_type } = self ;
72
80
73
81
PagedSearch { executor, params, resource_type, page_size }
74
82
}
75
-
76
- /// Execute the search
77
- pub async fn send ( self ) -> Result < impl Stream < Item = Result < R , Error > > , Error > {
78
- self . executor . search_unpaged ( self . params ) . await
79
- }
80
83
}
81
84
82
85
#[ derive( Debug ) ]
@@ -95,12 +98,10 @@ pub struct PagedSearch<E, R> {
95
98
96
99
impl < E , R > PagedSearch < E , R >
97
100
where
98
- E : SearchExecutor < R > + ' static ,
101
+ E : PagedSearchExecutor < R > ,
99
102
{
100
103
/// Execute the search
101
- pub async fn send (
102
- self ,
103
- ) -> Result < ( impl Stream < Item = Result < R , Error > > , Option < NextPageCursor < E , R > > ) , Error > {
104
+ pub async fn send ( self ) -> Result < ( E :: Stream , Option < NextPageCursor < E , R > > ) , Error > {
104
105
self . executor . search_paged ( self . params , self . page_size ) . await
105
106
}
106
107
}
@@ -121,36 +122,38 @@ pub struct NextPageCursor<E, R> {
121
122
122
123
impl < E , R > NextPageCursor < E , R >
123
124
where
124
- E : SearchExecutor < R > + ' static ,
125
+ E : PagedSearchExecutor < R > + ' static ,
125
126
{
126
127
pub fn new ( executor : E , next_page_url : Url ) -> Self {
127
128
Self { executor, next_page_url, resource_type : PhantomData }
128
129
}
129
130
130
- pub async fn next_page (
131
- self ,
132
- ) -> Result < ( impl Stream < Item = Result < R , Error > > , Option < Self > ) , Error > {
131
+ pub async fn next_page ( self ) -> Result < ( E :: Stream , Option < Self > ) , Error > {
133
132
self . executor . fetch_next_page ( self . next_page_url ) . await
134
133
}
135
134
}
136
135
137
136
#[ async_trait]
138
- pub trait SearchExecutor < R > : Sized {
139
- async fn search_unpaged (
140
- self ,
141
- params : SearchParameters ,
142
- ) -> Result < impl Stream < Item = Result < R , Error > > , Error > ;
137
+ pub trait UnpagedSearchExecutor < R > : Sized {
138
+ type Stream : Stream < Item = Result < R , Error > > ;
139
+
140
+ async fn search_unpaged ( self , params : SearchParameters ) -> Result < Self :: Stream , Error > ;
141
+ }
142
+
143
+ #[ async_trait]
144
+ pub trait PagedSearchExecutor < R > : Sized {
145
+ type Stream : Stream < Item = Result < R , Error > > ;
143
146
144
147
async fn search_paged (
145
148
self ,
146
149
params : SearchParameters ,
147
150
page_size : Option < u32 > ,
148
- ) -> Result < ( impl Stream < Item = Result < R , Error > > , Option < NextPageCursor < Self , R > > ) , Error > ;
151
+ ) -> Result < ( Self :: Stream , Option < NextPageCursor < Self , R > > ) , Error > ;
149
152
150
153
async fn fetch_next_page (
151
154
self ,
152
155
next_page_url : Url ,
153
- ) -> Result < ( impl Stream < Item = Result < R , Error > > , Option < NextPageCursor < Self , R > > ) , Error > ;
156
+ ) -> Result < ( Self :: Stream , Option < NextPageCursor < Self , R > > ) , Error > ;
154
157
}
155
158
156
159
impl < V : ' static > Client < V > {
@@ -159,7 +162,8 @@ impl<V: 'static> Client<V> {
159
162
/// matching included resources.
160
163
pub fn search < R > ( & self ) -> UnpagedSearch < Self , R >
161
164
where
162
- Self : SearchExecutor < R > ,
165
+ Self : UnpagedSearchExecutor < R > ,
166
+ R : Send ,
163
167
{
164
168
UnpagedSearch :: new ( self . clone ( ) )
165
169
}
0 commit comments