Struct modio::Query

source ·
pub struct Query<T> { /* private fields */ }
Expand description

Interface for retrieving search results.

Implementations§

source§

impl<T: DeserializeOwned + Send> Query<T>

source

pub async fn first(self) -> Result<Option<T>>

Returns the first search result.

source

pub async fn first_page(self) -> Result<Vec<T>>

Returns the first search result page.

source

pub async fn collect(self) -> Result<Vec<T>>

Returns the complete search result list.

source

pub async fn iter(self) -> Result<impl Stream<Item = Result<T>>>

Provides a stream over all search result items.

Beware that a Filter::with_limit will NOT limit the number of items returned by the stream, but limits the page size for the underlying API requests.

§Example
use futures_util::TryStreamExt;
use modio::filter::prelude::*;
use modio::types::id::Id;

let filter = Fulltext::eq("soldier");
let mut st = modio.game(Id::new(51)).mods().search(filter).iter().await?;

// Stream of `Mod`
while let Some(mod_) = st.try_next().await? {
    println!("{}. {}", mod_.id, mod_.name);
}

use futures_util::StreamExt;

// Retrieve the first 10 mods. (Default page size is `100`.)
let filter = Fulltext::eq("tftd") + with_limit(10);
let st = modio.game(Id::new(51)).mods().search(filter).iter().await?;
let mut st = st.take(10);

// Stream of `Mod`
while let Some(mod_) = st.try_next().await? {
    println!("{}. {}", mod_.id, mod_.name);
}
source

pub async fn paged(self) -> Result<impl Stream<Item = Result<Page<T>>>>

Provides a stream over all search result pages.

§Example
use futures_util::TryStreamExt;
use modio::filter::prelude::*;
use modio::types::id::Id;

let filter = Fulltext::eq("tftd").limit(10);
let mut st = modio
    .game(Id::new(51))
    .mods()
    .search(filter)
    .paged()
    .await?;

// Stream of paged results `Page<Mod>` with page size = 10
while let Some(page) = st.try_next().await? {
    println!("Page {}/{}", page.current(), page.page_count());
    for item in page {
        println!("  {}. {}", item.id, item.name);
    }
}

Auto Trait Implementations§

§

impl<T> Freeze for Query<T>

§

impl<T> !RefUnwindSafe for Query<T>

§

impl<T> Send for Query<T>
where T: Send,

§

impl<T> Sync for Query<T>
where T: Sync,

§

impl<T> Unpin for Query<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Query<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more