Trait RequestMethod

Source
pub trait RequestMethod: Sized
where Self::Method: From<Self>, for<'a> &'a Self::Method: From<&'a Self>,
{ type Method: Request; // Provided methods fn as_request(&self) -> &Self::Method { ... } fn into_request(self) -> Self::Method { ... } }
Expand description

Specify the Request method that should be used for a type.

Due to the way the Rust type system works, you can implement both PostRequest and GetRequest for the same type. To be able to implement Request for your type, this trait helps by allowing you to specify which request type should be used.

For example:

use restless_core::*;
use std::borrow::Cow;

struct MyRequest;

impl GetRequest for MyRequest {
    type Response = Vec<u8>;
    type Query = ();

    fn path(&self) -> Cow<'_, str> {
        "api/v1/request".into()
    }

    fn query(&self) -> Self::Query {}
}

impl RequestMethod for MyRequest {
    type Method = methods::Get<Self>;
}

Required Associated Types§

Source

type Method: Request

Method to use for this request.

Provided Methods§

Source

fn as_request(&self) -> &Self::Method

Borrow a Request.

Source

fn into_request(self) -> Self::Method

Turn this into an owned 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.

Implementors§