Trait AsyncResponse

Source
pub trait AsyncResponse:
    Send
    + Sync
    + 'static {
    // Required methods
    fn status(&self) -> u16;
    fn content_length(&self) -> Option<u64>;
    fn get_header(&self, header: &str) -> Result<Vec<String>>;
    fn text(&mut self) -> impl Future<Output = Result<String>> + Send;
    fn bytes(&mut self) -> impl Future<Output = Result<Vec<u8>>> + Send;

    // Provided method
    fn describe(&self, f: &mut Formatter<'_>) -> Result { ... }
}
Available on crate feature async only.
Expand description

Trait for asynchronous HTTP responses.

This trait provides methods for accessing the data in an HTTP response.

§Response Method Receivers

Note that the AsyncResponse trait uses &mut self receivers for content reading methods (text(), bytes(), etc.) to ensure object safety and dyn compatibility. This differs from the main nyquest crate which uses consuming self receivers.

Backend implementors should design their implementations with the understanding that these methods may be called only once per response instance, even though the signature allows multiple calls. The nyquest facade enforces this by consuming the response.

Required Methods§

Source

fn status(&self) -> u16

Returns the HTTP status code of this response.

Source

fn content_length(&self) -> Option<u64>

Returns the content-length of the response body, if known.

Source

fn get_header(&self, header: &str) -> Result<Vec<String>>

Gets all values for the specified header.

Source

fn text(&mut self) -> impl Future<Output = Result<String>> + Send

Reads the response body as text.

Source

fn bytes(&mut self) -> impl Future<Output = Result<Vec<u8>>> + Send

Reads the response body as bytes.

Provided Methods§

Source

fn describe(&self, f: &mut Formatter<'_>) -> Result

Provides a textual description of this response.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§