pub trait Resource: Clone {
type Destination: Clone + Send + Sync + 'static;
type RequestBody: BufStream;
type Buf: Buf;
type Body: BufStream<Item = Self::Buf, Error = Error>;
type Future: ResourceFuture<Body = Self::Body>;
// Required method
fn dispatch(
&mut self,
destination: Self::Destination,
route_match: &RouteMatch<'_>,
body: Self::RequestBody,
) -> Self::Future;
}Expand description
A Resource processes HTTP requests received by the service.
A single service is composed of one or more resources. A resource instance is created with a route set representing the set of routes that it is able to handle. The service merges the route sets together and uses it to match inbound requests.
When matching a route, the route set returns a Self::Destination value.
This value is then provided to Resource::dispatch and this is how the
resource instance knows which method to dispatch the request to.
Users are not expected to implement Resource themselves. Instead, the
impl_web! macro will generate a Resource implementation. The
implementation is then passed to ServiceBuilder to define the web service.
Required Associated Types§
Sourcetype Destination: Clone + Send + Sync + 'static
type Destination: Clone + Send + Sync + 'static
Token mapping a route to a resource method.
Sourcetype RequestBody: BufStream
type RequestBody: BufStream
The HTTP request body type.
Sourcetype Body: BufStream<Item = Self::Buf, Error = Error>
type Body: BufStream<Item = Self::Buf, Error = Error>
The HTTP response body type.
This value will yield one or more Self::Buf values.
Sourcetype Future: ResourceFuture<Body = Self::Body>
type Future: ResourceFuture<Body = Self::Body>
Response future
Required Methods§
Sourcefn dispatch(
&mut self,
destination: Self::Destination,
route_match: &RouteMatch<'_>,
body: Self::RequestBody,
) -> Self::Future
fn dispatch( &mut self, destination: Self::Destination, route_match: &RouteMatch<'_>, body: Self::RequestBody, ) -> Self::Future
Process the HTTP request and return the response asynchronously.
The HTTP request has already been matched against the route set before
calling this function. The destination and route_match arguments
provide the necessary context for the resource to process the matched
HTTP request.
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.