pub struct Response<T> {
pub rate_limit_status: RateLimit,
pub response: T,
}
Expand description
A helper struct to wrap response data with accompanying rate limit information.
This is returned by any function that calls a rate-limited method on Twitter, to allow for
inline checking of the rate-limit information without an extra call to
service::rate_limit_info
.
As this implements Deref
and DerefMut
, you can transparently use the contained response
’s
methods as if they were methods on this struct.
Fields§
§rate_limit_status: RateLimit
The latest rate-limit information returned with the request.
response: T
The decoded response from the request.
Implementations§
source§impl<T> Response<T>
impl<T> Response<T>
sourcepub fn map<F, U>(src: Response<T>, fun: F) -> Response<U>where
F: FnOnce(T) -> U,
pub fn map<F, U>(src: Response<T>, fun: F) -> Response<U>where
F: FnOnce(T) -> U,
Convert a Response<T>
to a Response<U>
by running its contained response through the
given function. This preserves its rate-limit information.
Note that this is not a member function, so as to not conflict with potential methods on the
contained T
.
sourcepub fn try_map<F, U, E>(src: Response<T>, fun: F) -> Result<Response<U>, E>where
F: FnOnce(T) -> Result<U, E>,
pub fn try_map<F, U, E>(src: Response<T>, fun: F) -> Result<Response<U>, E>where
F: FnOnce(T) -> Result<U, E>,
Attempt to convert a Response<T>
into a Response<U>
by running its contained response
through the given function, preserving its rate-limit information. If the conversion
function fails, an error is returned instead.
Note that this is not a member function, so as to not conflict with potential methods on the
contained T
.
sourcepub fn into<U>(src: Self) -> Response<U>where
T: Into<U>,
pub fn into<U>(src: Self) -> Response<U>where
T: Into<U>,
Converts a Response<T>
into a Response<U>
using the Into
trait.
This is implemented as a type function instead of the From
/Into
trait due to
implementation conflicts with the From<T> for T
implementation in the standard library.
It is also implemented as a function directly on the Response
type instead of as a member
function to not clash with the into()
function that would be available on the contained
T
.