pub struct ItemIterator<P>{ /* private fields */ }Expand description
Iterates over a collection of items or individual pages of items from a service.
You can asynchronously iterate over items returned by a collection request to a service, or asynchronously fetch pages of items if preferred.
§Examples
For clients that return a Pager, you can iterate over items across one or more pages:
let client = SecretClient::new(
"https://my-vault.vault.azure.net",
credential.clone(),
None,
)?;
// List secret properties using a Pager.
let mut pager = client.list_secret_properties(None)?;
while let Some(secret) = pager.try_next().await? {
println!("{}", secret.resource_id()?.name);
}If you want to iterate each page of items, you can call Pager::into_pages to get a PageIterator:
let client = SecretClient::new(
"https://my-vault.vault.azure.net",
credential.clone(),
None,
)?;
// Iterate each page of secrets using a PageIterator.
let mut pager = client.list_secret_properties(None)?.into_pages();
while let Some(page) = pager.try_next().await? {
let page = page.into_model()?;
for secret in page.value {
println!("{}", secret.resource_id()?.name);
}
}Implementations§
Source§impl<P> ItemIterator<P>
impl<P> ItemIterator<P>
Sourcepub fn new<F: Fn(PagerState, PagerOptions<'static>) -> PagerResultFuture<P> + Send + 'static>(
make_request: F,
options: Option<PagerOptions<'static>>,
) -> Self
pub fn new<F: Fn(PagerState, PagerOptions<'static>) -> PagerResultFuture<P> + Send + 'static>( make_request: F, options: Option<PagerOptions<'static>>, ) -> Self
Creates a ItemIterator from a callback that will be called repeatedly to request each page.
This method expect a callback that accepts a single PagerState parameter, and returns a PagerResult value asynchronously.
The result will be an asynchronous stream of Result values.
The first time your callback is called, it will be called with Option::None, indicating no next link/continuation token is present.
Your callback must return one of:
Ok(result)- The request succeeded, and the providedPagerResultindicates the value to return and if there are more pages.Err(..)- The request failed. The error will be yielded to the stream, the stream will end, and the callback will not be called again.
§Examples
To page results using a next link:
#[derive(serde::Deserialize)]
struct ListItemsResult {
items: Vec<String>,
next_link: Option<String>,
}
#[async_trait::async_trait]
impl Page for ListItemsResult {
type Item = String;
type IntoIter = <Vec<String> as IntoIterator>::IntoIter;
async fn into_items(self) -> Result<Self::IntoIter> {
Ok(self.items.into_iter())
}
}
let url = "https://example.com/my_paginated_api".parse().unwrap();
let mut base_req = Request::new(url, Method::Get);
let pager = ItemIterator::new(move |next_link: PagerState, options: PagerOptions<'static>| {
// The callback must be 'static, so you have to clone and move any values you want to use.
let pipeline = pipeline.clone();
let api_version = api_version.clone();
let mut req = base_req.clone();
Box::pin(async move {
if let PagerState::More(next_link) = next_link {
let next_link: Url = next_link.try_into().expect("expected Url");
// Ensure the api-version from the client is appended.
let qp = next_link
.query_pairs()
.filter(|(name, _)| name.ne("api-version"));
req
.url_mut()
.query_pairs_mut()
.clear()
.extend_pairs(qp)
.append_pair("api-version", &api_version);
}
let resp = pipeline
.send(&options.context, &mut req, None)
.await?;
let (status, headers, body) = resp.deconstruct();
let result: ListItemsResult = json::from_json(&body)?;
let resp: Response<ListItemsResult> = RawResponse::from_bytes(status, headers, body).into();
Ok(match result.next_link {
Some(next_link) => PagerResult::More {
response: resp,
continuation: PagerContinuation::Link(next_link.parse()?),
},
None => PagerResult::Done { response: resp }
})
})
}, None);To page results using headers:
#[derive(serde::Deserialize)]
struct ListItemsResult {
items: Vec<String>,
}
#[async_trait::async_trait]
impl Page for ListItemsResult {
type Item = String;
type IntoIter = <Vec<String> as IntoIterator>::IntoIter;
async fn into_items(self) -> Result<Self::IntoIter> {
Ok(self.items.into_iter())
}
}
let url = "https://example.com/my_paginated_api".parse().unwrap();
let mut base_req = Request::new(url, Method::Get);
let pager = ItemIterator::new(move |continuation, options| {
// The callback must be 'static, so you have to clone and move any values you want to use.
let pipeline = pipeline.clone();
let mut req = base_req.clone();
Box::pin(async move {
if let PagerState::More(continuation) = continuation {
req.insert_header("x-ms-continuation", continuation.as_ref().to_string());
}
let resp: Response<ListItemsResult> = pipeline
.send(&options.context, &mut req, None)
.await?
.into();
Ok(PagerResult::from_response_header(resp, &HeaderName::from_static("x-next-continuation")))
})
}, None);Sourcepub fn continuation(&self) -> Option<&PagerContinuation>
pub fn continuation(&self) -> Option<&PagerContinuation>
Gets the continuation token to pass to PagerOptions to resume paging in another iterator.
Sourcepub fn into_continuation(self) -> Option<PagerContinuation>
pub fn into_continuation(self) -> Option<PagerContinuation>
Gets the continuation token to pass to PagerOptions to resume paging in another iterator.
§Examples
This takes ownership of the iterator and can be useful when constructing a new iterator.
let pager1 = client.list_secret_properties(None)?;
assert!(pager1.try_next().await?.is_some());
let options = SecretClientListSecretPropertiesOptions {
method_options: PagerOptions {
continuation: pager1.into_continuation(),
..Default::default()
},
..Default::default()
};
let pager2 = client.list_secret_properties(Some(options))?;
assert!(pager2.try_next().await?.is_some());Sourcepub fn into_pages(self) -> PageIterator<P>
pub fn into_pages(self) -> PageIterator<P>
Gets a PageIterator to iterate over pages instead of items.
Resumes from the current page of items until after all items in the current page have been iterated to avoid skipping items in the current page.
Trait Implementations§
Source§impl<P> Debug for ItemIterator<P>
impl<P> Debug for ItemIterator<P>
Source§impl<P> FusedStream for ItemIterator<P>
impl<P> FusedStream for ItemIterator<P>
Source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
true if the stream should no longer be polled.Source§impl<P> Stream for ItemIterator<P>
impl<P> Stream for ItemIterator<P>
impl<'pin, P> Unpin for ItemIterator<P>
Auto Trait Implementations§
impl<P> !RefUnwindSafe for ItemIterator<P>
impl<P> !Sync for ItemIterator<P>
impl<P> !UnwindSafe for ItemIterator<P>
impl<P> Freeze for ItemIterator<P>
impl<P> Send for ItemIterator<P>
impl<P> UnsafeUnpin for ItemIterator<P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§impl<T> StreamExt for T
impl<T> StreamExt for T
Source§fn next(&mut self) -> Next<'_, Self> ⓘwhere
Self: Unpin,
fn next(&mut self) -> Next<'_, Self> ⓘwhere
Self: Unpin,
Source§fn into_future(self) -> StreamFuture<Self> ⓘ
fn into_future(self) -> StreamFuture<Self> ⓘ
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Source§fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
Source§fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
Source§fn collect<C>(self) -> Collect<Self, C> ⓘ
fn collect<C>(self) -> Collect<Self, C> ⓘ
Source§fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB> ⓘ
fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB> ⓘ
Source§fn concat(self) -> Concat<Self> ⓘ
fn concat(self) -> Concat<Self> ⓘ
Source§fn count(self) -> Count<Self> ⓘwhere
Self: Sized,
fn count(self) -> Count<Self> ⓘwhere
Self: Sized,
Source§fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F> ⓘ
fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F> ⓘ
Source§fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F> ⓘ
fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F> ⓘ
true if any element in stream satisfied a predicate. Read moreSource§fn all<Fut, F>(self, f: F) -> All<Self, Fut, F> ⓘ
fn all<Fut, F>(self, f: F) -> All<Self, Fut, F> ⓘ
true if all element in stream satisfied a predicate. Read moreSource§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_unordered(
self,
limit: impl Into<Option<usize>>,
) -> FlattenUnorderedWithFlowController<Self, ()>
fn flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> FlattenUnorderedWithFlowController<Self, ()>
Source§fn flat_map_unordered<U, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> FlatMapUnordered<Self, U, F>
fn flat_map_unordered<U, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> FlatMapUnordered<Self, U, F>
StreamExt::map but flattens nested Streams
and polls them concurrently, yielding items in any order, as they made
available. Read moreSource§fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
StreamExt::fold that holds internal state
and produces a new stream. Read moreSource§fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
true. Read moreSource§fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
true. Read moreSource§fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
Source§fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F> ⓘ
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F> ⓘ
Source§fn for_each_concurrent<Fut, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> ForEachConcurrent<Self, Fut, F> ⓘ
fn for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> ForEachConcurrent<Self, Fut, F> ⓘ
Source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n items of the underlying stream. Read moreSource§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n items of the underlying stream. Read moreSource§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
Self: Sized + 'a,
Source§fn buffered(self, n: usize) -> Buffered<Self>
fn buffered(self, n: usize) -> Buffered<Self>
Source§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
Source§fn zip<St>(self, other: St) -> Zip<Self, St>
fn zip<St>(self, other: St) -> Zip<Self, St>
Source§fn peekable(self) -> Peekable<Self>where
Self: Sized,
fn peekable(self) -> Peekable<Self>where
Self: Sized,
peek method. Read moreSource§fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
Source§fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
Source§fn forward<S>(self, sink: S) -> Forward<Self, S> ⓘ
fn forward<S>(self, sink: S) -> Forward<Self, S> ⓘ
Source§fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
Source§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn left_stream<B>(self) -> Either<Self, B> ⓘ
fn left_stream<B>(self) -> Either<Self, B> ⓘ
Source§fn right_stream<B>(self) -> Either<B, Self> ⓘ
fn right_stream<B>(self) -> Either<B, Self> ⓘ
Source§fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
Self: Unpin,
fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
Self: Unpin,
Stream::poll_next on Unpin
stream types.Source§fn select_next_some(&mut self) -> SelectNextSome<'_, Self> ⓘwhere
Self: Unpin + FusedStream,
fn select_next_some(&mut self) -> SelectNextSome<'_, Self> ⓘwhere
Self: Unpin + FusedStream,
Source§impl<S> TryStreamExt for S
impl<S> TryStreamExt for S
Source§fn err_into<E>(self) -> ErrInto<Self, E>
fn err_into<E>(self) -> ErrInto<Self, E>
Source§fn map_ok<T, F>(self, f: F) -> MapOk<Self, F>
fn map_ok<T, F>(self, f: F) -> MapOk<Self, F>
Source§fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
Source§fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
f. Read moreSource§fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F>
fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F>
f. Read moreSource§fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F>
fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F>
Source§fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn try_next(&mut self) -> TryNext<'_, Self> ⓘwhere
Self: Unpin,
fn try_next(&mut self) -> TryNext<'_, Self> ⓘwhere
Self: Unpin,
Source§fn try_for_each<Fut, F>(self, f: F) -> TryForEach<Self, Fut, F> ⓘ
fn try_for_each<Fut, F>(self, f: F) -> TryForEach<Self, Fut, F> ⓘ
Source§fn try_skip_while<Fut, F>(self, f: F) -> TrySkipWhile<Self, Fut, F>
fn try_skip_while<Fut, F>(self, f: F) -> TrySkipWhile<Self, Fut, F>
true. Read moreSource§fn try_take_while<Fut, F>(self, f: F) -> TryTakeWhile<Self, Fut, F>
fn try_take_while<Fut, F>(self, f: F) -> TryTakeWhile<Self, Fut, F>
true. Read moreSource§fn try_for_each_concurrent<Fut, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> TryForEachConcurrent<Self, Fut, F> ⓘ
fn try_for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> TryForEachConcurrent<Self, Fut, F> ⓘ
Source§fn try_collect<C>(self) -> TryCollect<Self, C> ⓘ
fn try_collect<C>(self) -> TryCollect<Self, C> ⓘ
Source§fn try_chunks(self, capacity: usize) -> TryChunks<Self>where
Self: Sized,
fn try_chunks(self, capacity: usize) -> TryChunks<Self>where
Self: Sized,
Source§fn try_ready_chunks(self, capacity: usize) -> TryReadyChunks<Self>where
Self: Sized,
fn try_ready_chunks(self, capacity: usize) -> TryReadyChunks<Self>where
Self: Sized,
Source§fn try_filter<Fut, F>(self, f: F) -> TryFilter<Self, Fut, F>
fn try_filter<Fut, F>(self, f: F) -> TryFilter<Self, Fut, F>
Source§fn try_filter_map<Fut, F, T>(self, f: F) -> TryFilterMap<Self, Fut, F>
fn try_filter_map<Fut, F, T>(self, f: F) -> TryFilterMap<Self, Fut, F>
Source§fn try_flatten_unordered(
self,
limit: impl Into<Option<usize>>,
) -> TryFlattenUnordered<Self>
fn try_flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> TryFlattenUnordered<Self>
Source§fn try_flatten(self) -> TryFlatten<Self>
fn try_flatten(self) -> TryFlatten<Self>
Source§fn try_fold<T, Fut, F>(self, init: T, f: F) -> TryFold<Self, Fut, T, F> ⓘ
fn try_fold<T, Fut, F>(self, init: T, f: F) -> TryFold<Self, Fut, T, F> ⓘ
Source§fn try_concat(self) -> TryConcat<Self> ⓘ
fn try_concat(self) -> TryConcat<Self> ⓘ
Source§fn try_buffer_unordered(self, n: usize) -> TryBufferUnordered<Self>
fn try_buffer_unordered(self, n: usize) -> TryBufferUnordered<Self>
Source§fn try_buffered(self, n: usize) -> TryBuffered<Self>
fn try_buffered(self, n: usize) -> TryBuffered<Self>
Source§fn try_poll_next_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Ok, Self::Error>>>where
Self: Unpin,
fn try_poll_next_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Ok, Self::Error>>>where
Self: Unpin,
TryStream::try_poll_next on Unpin
stream types.Source§fn into_async_read(self) -> IntoAsyncRead<Self>
fn into_async_read(self) -> IntoAsyncRead<Self>
AsyncBufRead. Read moreSource§fn try_all<Fut, F>(self, f: F) -> TryAll<Self, Fut, F> ⓘ
fn try_all<Fut, F>(self, f: F) -> TryAll<Self, Fut, F> ⓘ
Err is encountered or if an Ok item is found
that does not satisfy the predicate. Read more