[][src]Struct egg_mode::user::UserSearch

#[must_use = "search iterators are lazy and do nothing unless consumed"]
pub struct UserSearch {
    pub page_num: i32,
    pub page_size: i32,
    // some fields omitted
}

Represents an active user search.

This struct is returned by search and is meant to be used as a Stream. That means all the Stream adaptors are available:

use futures::{Stream, StreamExt, TryStreamExt};

egg_mode::user::search("rustlang", &token).take(10).try_for_each(|resp| {
    println!("{}", resp.screen_name);
    futures::future::ready(Ok(()))
}).await.unwrap();

You can even collect the results, letting you get one set of rate-limit information for the entire search setup:

use futures::{Stream, StreamExt, TryStreamExt};
use egg_mode::Response;
use egg_mode::user::TwitterUser;
use egg_mode::error::Error;

// Because Streams don't have a FromIterator adaptor, we load all the responses first, then
// collect them into the final Vec
let names: Result<Vec<TwitterUser>, Error> =
    egg_mode::user::search("rustlang", &token)
        .take(10)
        .try_collect::<Vec<_>>()
        .await
        .map(|res| res.into_iter().collect());

UserSearch has a couple adaptors of its own that you can use before consuming it. with_page_size will let you set how many users are pulled in with a single network call, and start_at_page lets you start your search at a specific page. Calling either of these after starting iteration will clear any current results.

The Stream implementation yields Response<TwitterUser> on a successful iteration, and Error for errors, so network errors, rate-limit errors and other issues are passed directly through in poll(). The Stream implementation will allow you to poll again after an error to re-initiate the late network call; this way, you can wait for your network connection to return or for your rate limit to refresh and try again from the same position.

Manual paging

The Stream implementation works by loading in a page of results (with size set by default or by with_page_size/the page_size field) when it's polled, and serving the individual elements from that locally-cached page until it runs out. This can be nice, but it also means that your only warning that something involves a network call is that the stream returns Poll::Pending, by which time the network call has already started. If you want to know that ahead of time, that's where the call() method comes in. By using call(), you can get a page of results directly from Twitter. With that you can iterate over the results and page forward and backward as needed:

let mut search = egg_mode::user::search("rustlang", &token).with_page_size(20);
let resp = search.call().await.unwrap();

for user in resp.response {
   println!("{} (@{})", user.name, user.screen_name);
}

search.page_num += 1;
let resp = search.call().await.unwrap();

for user in resp.response {
   println!("{} (@{})", user.name, user.screen_name);
}

Fields

page_num: i32

The current page of results being returned, starting at 1.

page_size: i32

The number of user records per page of results. Defaults to 10, maximum of 20.

Methods

impl UserSearch[src]

pub fn with_page_size(self, page_size: i32) -> Self[src]

Sets the page size used for the search query.

Calling this will invalidate any current search results, making the next call to next() perform a network call.

pub fn start_at_page(self, page_num: i32) -> Self[src]

Sets the starting page number for the search query.

The search method begins numbering pages at 1. Calling this will invalidate any current search results, making the next call to next() perform a network call.

pub fn call(&self) -> impl Future<Output = Result<Response<Vec<TwitterUser>>>>[src]

Performs the search for the current page of results.

This will automatically be called if you use the UserSearch as an iterator. This method is made public for convenience if you want to manage the pagination yourself. Remember to change page_num between calls.

Trait Implementations

impl Stream for UserSearch[src]

type Item = Result<TwitterUser, Error>

Values yielded by the stream.

Auto Trait Implementations

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<T> Same<T> for T

type Output = T

Should always be Self

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

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<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]

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