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 { ... }
}
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§
Sourcefn content_length(&self) -> Option<u64>
fn content_length(&self) -> Option<u64>
Returns the content-length of the response body, if known.
Sourcefn get_header(&self, header: &str) -> Result<Vec<String>>
fn get_header(&self, header: &str) -> Result<Vec<String>>
Gets all values for the specified header.
Provided Methods§
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.