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".

Implementations on Foreign Types§

Source§

impl FromCall for Bytes

The raw request body as bytes.

Source§

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

Source§

impl FromCall for String

The raw request body as text.

Fails with 400 Bad Request if the body is not valid UTF-8. For bytes that may not be text, extract Bytes instead.

Source§

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

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 FromCall for Multipart

Source§

impl FromCall for MultipartStream

Source§

impl FromCall for Payload

Source§

impl<L, R> FromCall for Either<L, R>
where L: FromCall, R: FromCall,

Source§

impl<T: FromCallParts> FromCall for T

Any parts extractor can also be the final argument.

do_not_recommend: when a body extractor is wrongly placed in a leading position, rustc would otherwise suggest implementing FromCallParts for it — which is the one thing that must not happen, since it would let the body be consumed twice.

Source§

impl<T> FromCall for Form<T>