pub trait Cursor<T>: Sealedwhere
T: Send,{
// Required method
fn next(&mut self) -> impl Future<Output = CursorResult<T>> + Send;
// Provided methods
fn collect(self) -> impl Future<Output = (Vec<T>, CursorError)> + Send
where Self: Sized + Send { ... }
fn filter<F, Fut>(
self,
f: F
) -> impl Future<Output = CursorFilter<T, Self, F>> + Send
where Self: Sized + Send,
F: FnMut(&T) -> Fut + Send,
Fut: Future<Output = bool> { ... }
fn map<U, F, Fut>(
self,
f: F
) -> impl Future<Output = CursorMap<T, Self, F>> + Send
where U: Send,
Self: Sized + Send,
F: FnMut(T) -> Fut + Send,
Fut: Future<Output = U> { ... }
}
Expand description
An asynchronous iterator that supports Continuation
.
A continuation is an opaque token that represents the position of the cursor. A continuation can be at the begin marker which is the position before any items are returned. It can be somewhere in the middle or it can be at the end marker position. End marker would be the position after all the items are returned.
When a Cursor::next
stops producing values and assuming there
was no FdbError
, then the reason for not producing the values
is reported using NoNextReason
. This is returned as part of
CursorResult
.
No next reasons are fundamentally distinguished between those that are due to the data itself (in-band) and those that are due to the environment / context (out-of-band). For example, running out of data or having returned the maximum number of values requested are in-band, while reaching a limit on the number of key-value pairs scanned by the transaction or the time that a transaction has been open are out-of-band.
Required Methods§
sourcefn next(&mut self) -> impl Future<Output = CursorResult<T>> + Send
fn next(&mut self) -> impl Future<Output = CursorResult<T>> + Send
Asynchronously return the next result from this cursor.
Provided Methods§
sourcefn collect(self) -> impl Future<Output = (Vec<T>, CursorError)> + Sendwhere
Self: Sized + Send,
fn collect(self) -> impl Future<Output = (Vec<T>, CursorError)> + Sendwhere Self: Sized + Send,
Drain the cursor pushing all emitted values into a collection.
sourcefn filter<F, Fut>(
self,
f: F
) -> impl Future<Output = CursorFilter<T, Self, F>> + Sendwhere
Self: Sized + Send,
F: FnMut(&T) -> Fut + Send,
Fut: Future<Output = bool>,
fn filter<F, Fut>( self, f: F ) -> impl Future<Output = CursorFilter<T, Self, F>> + Sendwhere Self: Sized + Send, F: FnMut(&T) -> Fut + Send, Fut: Future<Output = bool>,
Filters the values produced by this cursor according to the provided predicate.
Note
Unlike a general iterator, the computation that you can do
inside the async closure is limited. Specifically the closure
FnMut(&T) -> impl Future<Output = bool>
does not provide a
mechanism to return an error that might possibly occur within
the closure.
If you need this feature, you will need to build the loop yourself and handle the issue of how and which continuation to return that would be useful to the caller.
Also, since Cursor
is a sealed class, this method is
primarily meant for types defined in this crate.
sourcefn map<U, F, Fut>(
self,
f: F
) -> impl Future<Output = CursorMap<T, Self, F>> + Sendwhere
U: Send,
Self: Sized + Send,
F: FnMut(T) -> Fut + Send,
Fut: Future<Output = U>,
fn map<U, F, Fut>( self, f: F ) -> impl Future<Output = CursorMap<T, Self, F>> + Sendwhere U: Send, Self: Sized + Send, F: FnMut(T) -> Fut + Send, Fut: Future<Output = U>,
Map this cursor’s items to a different type, returning a new cursor of the resulting type.
Note
Unlike a general iterator, the computation that you can do
inside the async closure is limited. Specifically the closure
FnMut(T) -> impl Future<Output = U>
does not provide a
mechanism to return an error that might possibly occur within
the closure.
If you need this feature, you will need to build the loop yourself and handle the issue of how and which continuation to return that would be useful to the caller.
Also, since Cursor
is a sealed class, this method is
primarily meant for types defined in this crate.