Skip to main content

FromCall

Trait FromCall 

Source
pub trait FromCall: Sized + Send {
    // Required method
    fn from_call<'async_trait>(
        call: Call,
    ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

Extract a value by consuming the whole Call.

Because it takes the Call by value, a FromCall extractor may appear only as the last handler argument. Body-consuming extractors (such as a JSON body) implement this directly. Every FromCallParts type is automatically a FromCall via a blanket impl, and Call itself is FromCall (so a |c: Call| handler is just the last-argument case).

use churust_core::{Call, FromCall};
use http::{HeaderMap, Method};
use bytes::Bytes;
let c = Call::new(Method::GET, "/".parse().unwrap(), HeaderMap::new(), Bytes::new());
// `Call` is itself a `FromCall`:
let back = Call::from_call(c).await.unwrap();
assert_eq!(back.method(), &Method::GET);

Required Methods§

Source

fn from_call<'async_trait>( call: Call, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: 'async_trait,

Build Self by consuming the call, or return an Error (which the handler renders as the response).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl FromCall for Call

The whole Call as the final argument (Ktor call-style base case). NOTE: deliberately NOT FromCallParts — that would conflict with the blanket impl above.

Source§

impl<T: FromCallParts> FromCall for T

Any parts extractor can also be the final argument.