pub trait AsyncClient {
type Error: Error + Send + Sync + 'static;
// Required method
fn send(
&self,
request: HttpRequest,
) -> impl Future<Output = Result<HttpResponse, Self::Error>> + Send;
}Expand description
The same, for a caller inside a runtime. Send on the future so that a
call can be tokio::spawned.
Required Associated Types§
Required Methods§
fn send( &self, request: HttpRequest, ) -> impl Future<Output = Result<HttpResponse, Self::Error>> + Send
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<C: AsyncClient + ?Sized> AsyncClient for &C
The same for the async flavour, for the same reason and at the same cost.
impl<C: AsyncClient + ?Sized> AsyncClient for &C
The same for the async flavour, for the same reason and at the same cost.
Two things differ. The future handed back is C’s own and the trait already
declares that one Send, so nothing here asks for C: Sync: what crosses a
tokio::spawn is the inner future, not the reference, and a client whose
answer is ready before the future is built is free to be !Sync. And the
trait returns impl Future, which makes it dyn-incompatible, so there is no
&dyn AsyncClient for ?Sized to reach here — it is written this way so the
two impls are one shape rather than two rules to remember.