[][src]Struct mongodb::Cursor

pub struct Cursor { /* fields omitted */ }

A Cursor streams the result of a query. When a query is made, a Cursor will be returned with the first batch of results from the server; the documents will be returned as the Cursor is iterated. When the batch is exhausted and if there are more results, the Cursor will fetch the next batch of documents, and so forth until the results are exhausted. Note that because of this batching, additional network I/O may occur on any given call to Cursor::next. Because of this, a Cursor iterates over Result<Document> items rather than simply Document items.

The batch size of the Cursor can be configured using the options to the method that returns it. For example, setting the batch_size field of FindOptions will set the batch size of the Cursor returned by Collection::find.

Note that the batch size determines both the number of documents stored in memory by the Cursor at a given time as well as the total number of network round-trips needed to fetch all results from the server; both of these factors should be taken into account when choosing the optimal batch size.

A cursor can be used like any other Iterator. The simplest way is just to iterate over the documents it yields:

for doc in cursor {
  println!("{}", doc?)
}

Additionally, all the other methods that an Iterator has are available on Cursor as well. For instance, if the number of results from a query is known to be small, it might make sense to collect them into a vector:

let results: Vec<Result<Document>> = cursor.collect();

Trait Implementations

impl Debug for Cursor[src]

impl Drop for Cursor[src]

impl Iterator for Cursor[src]

type Item = Result<Document>

The type of the elements being iterated over.

Auto Trait Implementations

impl !RefUnwindSafe for Cursor

impl Send for Cursor

impl Sync for Cursor

impl Unpin for Cursor

impl !UnwindSafe for Cursor

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<I> IteratorRandom for I where
    I: Iterator
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,