pub trait RequestMethod: Sized{
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§
Provided Methods§
Sourcefn as_request(&self) -> &Self::Method
fn as_request(&self) -> &Self::Method
Borrow a Request
.
Sourcefn into_request(self) -> Self::Method
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.