Skip to main content

Transport

Trait Transport 

Source
pub trait Transport: Send + Sync {
    // Required methods
    fn send(
        &self,
        request: &Request,
    ) -> impl Future<Output = Result<RawResponse, TransportError>> + Send;
    fn sleep(&self, duration: Duration) -> impl Future<Output = ()> + Send;
}
Available on crate feature rest only.
Expand description

The Adapter-provided way to send one HTTP request and to sleep; the REST client’s only contact with the platform (worker::Fetch on Cloudflare, reqwest natively).

Implementations send exactly the given request: no retries, no redirects to follow for Discord, no status handling. Non-2xx statuses are a normal RawResponse, only failures to get any response at all are a TransportError.

Futures are Send so REST calls can run on any thread (ADR 0012); single-threaded platforms wrap theirs (worker::send::SendFuture on Cloudflare).

Required Methods§

Source

fn send( &self, request: &Request, ) -> impl Future<Output = Result<RawResponse, TransportError>> + Send

Sends request and returns Discord’s response, whatever its status

Source

fn sleep(&self, duration: Duration) -> impl Future<Output = ()> + Send

Waits out a rate limit

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<T: Transport + ?Sized> Transport for &T

Source§

async fn send(&self, request: &Request) -> Result<RawResponse, TransportError>

Source§

async fn sleep(&self, duration: Duration)

Source§

impl<T: Transport + ?Sized> Transport for Arc<T>

Source§

async fn send(&self, request: &Request) -> Result<RawResponse, TransportError>

Source§

async fn sleep(&self, duration: Duration)

Implementors§

Source§

impl Transport for ReqwestTransport

Available on crate feature reqwest only.