pub struct Query<T> { /* private fields */ }
Expand description
Interface for retrieving search results.
Implementations§
source§impl<T: DeserializeOwned + Send> Query<T>
impl<T: DeserializeOwned + Send> Query<T>
sourcepub async fn first_page(self) -> Result<Vec<T>>
pub async fn first_page(self) -> Result<Vec<T>>
Returns the first search result page.
sourcepub async fn iter(self) -> Result<impl Stream<Item = Result<T>>>
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);
}
sourcepub async fn paged(self) -> Result<impl Stream<Item = Result<Page<T>>>>
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> 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
Mutably borrows from an owned value. Read more