Expand description
HTTP responses structure containing response data and headers.
By default the send()
function of the Request
structure will
return a Response<Vec<u8>>
. Convenience helpers exist for
decoding a string via Response::as_string
or to a
serde
-compatible type with Response::as_json
(if the
json
-feature is enabled).
Fields
status: u32
HTTP status code of the response.
headers: HashMap<String, String>
HTTP headers returned from the remote.
body: T
Body data from the HTTP response.
Implementations
sourceimpl<T> Response<T>
impl<T> Response<T>
sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check whether the status code of this HTTP response is a success (i.e. in the 200-299 range).
sourcepub fn error_for_status<F, E>(self, closure: F) -> Result<Self, E> where
F: FnOnce(Self) -> E,
pub fn error_for_status<F, E>(self, closure: F) -> Result<Self, E> where
F: FnOnce(Self) -> E,
Check whether a request succeeded using Request::is_success
and let users provide a closure that creates a custom error
from the request if it did not.
This function exists for convenience to avoid having to write
repetitive if !response.is_success() { ... }
blocks.
Trait Implementations
impl<T> StructuralPartialEq for Response<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Response<T> where
T: RefUnwindSafe,
impl<T> Send for Response<T> where
T: Send,
impl<T> Sync for Response<T> where
T: Sync,
impl<T> Unpin for Response<T> where
T: Unpin,
impl<T> UnwindSafe for Response<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more