[][src]Trait tower_web::routing::Resource

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>;
    fn dispatch(
        &mut self,
        destination: Self::Destination,
        route_match: &RouteMatch,
        body: Self::RequestBody
    ) -> Self::Future; }

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.

Associated Types

type Destination: Clone + Send + Sync + 'static

Token mapping a route to a resource method.

type RequestBody: BufStream

The HTTP request body type.

type Buf: Buf

Buffer type yielded by the response body.

type Body: BufStream<Item = Self::Buf, Error = Error>

The HTTP response body type.

This value will yield one or more Self::Buf values.

type Future: ResourceFuture<Body = Self::Body>

Response future

Loading content...

Required methods

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.

Loading content...

Implementations on Foreign Types

impl<R0> Resource for (R0,) where
    R0: Resource
[src]

type Destination = Either1<R0::Destination>

type RequestBody = R0::RequestBody

type Buf = Either1<R0::Buf>

type Body = Either1<R0::Body>

type Future = Either1<R0::Future>

impl<R0, R1> Resource for (R0, R1) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either2<R0::Destination, R1::Destination>

type RequestBody = R0::RequestBody

type Buf = Either2<R0::Buf, R1::Buf>

type Body = Either2<R0::Body, R1::Body>

type Future = Either2<R0::Future, R1::Future>

impl<R0, R1, R2> Resource for (R0, R1, R2) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either3<R0::Destination, R1::Destination, R2::Destination>

type RequestBody = R0::RequestBody

type Buf = Either3<R0::Buf, R1::Buf, R2::Buf>

type Body = Either3<R0::Body, R1::Body, R2::Body>

type Future = Either3<R0::Future, R1::Future, R2::Future>

impl<R0, R1, R2, R3> Resource for (R0, R1, R2, R3) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either4<R0::Destination, R1::Destination, R2::Destination, R3::Destination>

type RequestBody = R0::RequestBody

type Buf = Either4<R0::Buf, R1::Buf, R2::Buf, R3::Buf>

type Body = Either4<R0::Body, R1::Body, R2::Body, R3::Body>

type Future = Either4<R0::Future, R1::Future, R2::Future, R3::Future>

impl<R0, R1, R2, R3, R4> Resource for (R0, R1, R2, R3, R4) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>,
    R4: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either5<R0::Destination, R1::Destination, R2::Destination, R3::Destination, R4::Destination>

type RequestBody = R0::RequestBody

type Buf = Either5<R0::Buf, R1::Buf, R2::Buf, R3::Buf, R4::Buf>

type Body = Either5<R0::Body, R1::Body, R2::Body, R3::Body, R4::Body>

type Future = Either5<R0::Future, R1::Future, R2::Future, R3::Future, R4::Future>

impl<R0, R1, R2, R3, R4, R5> Resource for (R0, R1, R2, R3, R4, R5) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>,
    R4: Resource<RequestBody = R0::RequestBody>,
    R5: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either6<R0::Destination, R1::Destination, R2::Destination, R3::Destination, R4::Destination, R5::Destination>

type RequestBody = R0::RequestBody

type Buf = Either6<R0::Buf, R1::Buf, R2::Buf, R3::Buf, R4::Buf, R5::Buf>

type Body = Either6<R0::Body, R1::Body, R2::Body, R3::Body, R4::Body, R5::Body>

type Future = Either6<R0::Future, R1::Future, R2::Future, R3::Future, R4::Future, R5::Future>

impl<R0, R1, R2, R3, R4, R5, R6> Resource for (R0, R1, R2, R3, R4, R5, R6) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>,
    R4: Resource<RequestBody = R0::RequestBody>,
    R5: Resource<RequestBody = R0::RequestBody>,
    R6: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either7<R0::Destination, R1::Destination, R2::Destination, R3::Destination, R4::Destination, R5::Destination, R6::Destination>

type RequestBody = R0::RequestBody

type Buf = Either7<R0::Buf, R1::Buf, R2::Buf, R3::Buf, R4::Buf, R5::Buf, R6::Buf>

type Body = Either7<R0::Body, R1::Body, R2::Body, R3::Body, R4::Body, R5::Body, R6::Body>

type Future = Either7<R0::Future, R1::Future, R2::Future, R3::Future, R4::Future, R5::Future, R6::Future>

impl<R0, R1, R2, R3, R4, R5, R6, R7> Resource for (R0, R1, R2, R3, R4, R5, R6, R7) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>,
    R4: Resource<RequestBody = R0::RequestBody>,
    R5: Resource<RequestBody = R0::RequestBody>,
    R6: Resource<RequestBody = R0::RequestBody>,
    R7: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either8<R0::Destination, R1::Destination, R2::Destination, R3::Destination, R4::Destination, R5::Destination, R6::Destination, R7::Destination>

type RequestBody = R0::RequestBody

type Buf = Either8<R0::Buf, R1::Buf, R2::Buf, R3::Buf, R4::Buf, R5::Buf, R6::Buf, R7::Buf>

type Body = Either8<R0::Body, R1::Body, R2::Body, R3::Body, R4::Body, R5::Body, R6::Body, R7::Body>

type Future = Either8<R0::Future, R1::Future, R2::Future, R3::Future, R4::Future, R5::Future, R6::Future, R7::Future>

impl<R0, R1, R2, R3, R4, R5, R6, R7, R8> Resource for (R0, R1, R2, R3, R4, R5, R6, R7, R8) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>,
    R4: Resource<RequestBody = R0::RequestBody>,
    R5: Resource<RequestBody = R0::RequestBody>,
    R6: Resource<RequestBody = R0::RequestBody>,
    R7: Resource<RequestBody = R0::RequestBody>,
    R8: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either9<R0::Destination, R1::Destination, R2::Destination, R3::Destination, R4::Destination, R5::Destination, R6::Destination, R7::Destination, R8::Destination>

type RequestBody = R0::RequestBody

type Buf = Either9<R0::Buf, R1::Buf, R2::Buf, R3::Buf, R4::Buf, R5::Buf, R6::Buf, R7::Buf, R8::Buf>

type Body = Either9<R0::Body, R1::Body, R2::Body, R3::Body, R4::Body, R5::Body, R6::Body, R7::Body, R8::Body>

type Future = Either9<R0::Future, R1::Future, R2::Future, R3::Future, R4::Future, R5::Future, R6::Future, R7::Future, R8::Future>

impl<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9> Resource for (R0, R1, R2, R3, R4, R5, R6, R7, R8, R9) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>,
    R4: Resource<RequestBody = R0::RequestBody>,
    R5: Resource<RequestBody = R0::RequestBody>,
    R6: Resource<RequestBody = R0::RequestBody>,
    R7: Resource<RequestBody = R0::RequestBody>,
    R8: Resource<RequestBody = R0::RequestBody>,
    R9: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either10<R0::Destination, R1::Destination, R2::Destination, R3::Destination, R4::Destination, R5::Destination, R6::Destination, R7::Destination, R8::Destination, R9::Destination>

type RequestBody = R0::RequestBody

type Buf = Either10<R0::Buf, R1::Buf, R2::Buf, R3::Buf, R4::Buf, R5::Buf, R6::Buf, R7::Buf, R8::Buf, R9::Buf>

type Body = Either10<R0::Body, R1::Body, R2::Body, R3::Body, R4::Body, R5::Body, R6::Body, R7::Body, R8::Body, R9::Body>

type Future = Either10<R0::Future, R1::Future, R2::Future, R3::Future, R4::Future, R5::Future, R6::Future, R7::Future, R8::Future, R9::Future>

impl<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10> Resource for (R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>,
    R4: Resource<RequestBody = R0::RequestBody>,
    R5: Resource<RequestBody = R0::RequestBody>,
    R6: Resource<RequestBody = R0::RequestBody>,
    R7: Resource<RequestBody = R0::RequestBody>,
    R8: Resource<RequestBody = R0::RequestBody>,
    R9: Resource<RequestBody = R0::RequestBody>,
    R10: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either11<R0::Destination, R1::Destination, R2::Destination, R3::Destination, R4::Destination, R5::Destination, R6::Destination, R7::Destination, R8::Destination, R9::Destination, R10::Destination>

type RequestBody = R0::RequestBody

type Buf = Either11<R0::Buf, R1::Buf, R2::Buf, R3::Buf, R4::Buf, R5::Buf, R6::Buf, R7::Buf, R8::Buf, R9::Buf, R10::Buf>

type Body = Either11<R0::Body, R1::Body, R2::Body, R3::Body, R4::Body, R5::Body, R6::Body, R7::Body, R8::Body, R9::Body, R10::Body>

type Future = Either11<R0::Future, R1::Future, R2::Future, R3::Future, R4::Future, R5::Future, R6::Future, R7::Future, R8::Future, R9::Future, R10::Future>

impl<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11> Resource for (R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11) where
    R0: Resource,
    R1: Resource<RequestBody = R0::RequestBody>,
    R2: Resource<RequestBody = R0::RequestBody>,
    R3: Resource<RequestBody = R0::RequestBody>,
    R4: Resource<RequestBody = R0::RequestBody>,
    R5: Resource<RequestBody = R0::RequestBody>,
    R6: Resource<RequestBody = R0::RequestBody>,
    R7: Resource<RequestBody = R0::RequestBody>,
    R8: Resource<RequestBody = R0::RequestBody>,
    R9: Resource<RequestBody = R0::RequestBody>,
    R10: Resource<RequestBody = R0::RequestBody>,
    R11: Resource<RequestBody = R0::RequestBody>, 
[src]

type Destination = Either12<R0::Destination, R1::Destination, R2::Destination, R3::Destination, R4::Destination, R5::Destination, R6::Destination, R7::Destination, R8::Destination, R9::Destination, R10::Destination, R11::Destination>

type RequestBody = R0::RequestBody

type Buf = Either12<R0::Buf, R1::Buf, R2::Buf, R3::Buf, R4::Buf, R5::Buf, R6::Buf, R7::Buf, R8::Buf, R9::Buf, R10::Buf, R11::Buf>

type Body = Either12<R0::Body, R1::Body, R2::Body, R3::Body, R4::Body, R5::Body, R6::Body, R7::Body, R8::Body, R9::Body, R10::Body, R11::Body>

type Future = Either12<R0::Future, R1::Future, R2::Future, R3::Future, R4::Future, R5::Future, R6::Future, R7::Future, R8::Future, R9::Future, R10::Future, R11::Future>

Loading content...

Implementors

impl<B> Resource for Unit<B> where
    B: BufStream
[src]

type Destination = ()

type RequestBody = B

type Buf = <Self::Body as BufStream>::Item

type Body = Map<String>

type Future = FutureResult<Response<Self::Body>, Error>

Loading content...