Trait Extract

Source
pub trait Extract<B: BufStream>: 'static + Sized {
    type Future: ExtractFuture<Item = Self>;

    // Required method
    fn extract(context: &Context<'_>) -> Self::Future;

    // Provided methods
    fn extract_body(context: &Context<'_>, body: B) -> Self::Future { ... }
    fn requires_body(callsite: &CallSite) -> bool { ... }
}
Expand description

Extract a value from an HTTP request.

The extracted value does not need to be produced immediately. Implementations of Extract are able to perform asynchronous processing.

The trait is generic over B: BufStream, which represents the HTTP request body stream.

Required Associated Types§

Source

type Future: ExtractFuture<Item = Self>

The future representing the completion of the extraction logic.

Required Methods§

Source

fn extract(context: &Context<'_>) -> Self::Future

Extract the argument from the HTTP request.

This function is not provide the HTTP request body. Implementations of this function must ensure that the request HEAD (request URI and headers) are sufficient for extracting the value.

Provided Methods§

Source

fn extract_body(context: &Context<'_>, body: B) -> Self::Future

Extract the argument using the HTTP request body.

Doing so will usually involve deserializing the contents of the HTTP request body to the target value being extracted.

Source

fn requires_body(callsite: &CallSite) -> bool

Returns true if extracting the type requires body.

Only a single resource method argument may extract using the HTTP request body. This function allows enforcing this requirement.

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.

Implementations on Foreign Types§

Source§

impl<B: BufStream> Extract<B> for Value

Source§

type Future = SerdeFuture<Value, B>

Source§

fn extract(ctx: &Context<'_>) -> Self::Future

Source§

fn extract_body(ctx: &Context<'_>, body: B) -> Self::Future

Source§

fn requires_body(callsite: &CallSite) -> bool

Source§

impl<B: BufStream> Extract<B> for i8

Source§

impl<B: BufStream> Extract<B> for i16

Source§

impl<B: BufStream> Extract<B> for i32

Source§

impl<B: BufStream> Extract<B> for i64

Source§

impl<B: BufStream> Extract<B> for u8

Source§

impl<B: BufStream> Extract<B> for u16

Source§

impl<B: BufStream> Extract<B> for u32

Source§

impl<B: BufStream> Extract<B> for u64

Source§

impl<B: BufStream> Extract<B> for String

Source§

type Future = ExtractString<B>

Source§

fn extract(ctx: &Context<'_>) -> Self::Future

Source§

fn extract_body(ctx: &Context<'_>, body: B) -> Self::Future

Source§

fn requires_body(callsite: &CallSite) -> bool

Source§

impl<B: BufStream> Extract<B> for Vec<u8>

Source§

type Future = ExtractBytes<Vec<u8>, B>

Source§

fn extract(ctx: &Context<'_>) -> Self::Future

Source§

fn extract_body(ctx: &Context<'_>, body: B) -> Self::Future

Source§

fn requires_body(callsite: &CallSite) -> bool

Source§

impl<B: BufStream> Extract<B> for OsString

Source§

impl<B: BufStream> Extract<B> for PathBuf

Source§

impl<T, B: BufStream> Extract<B> for Option<T>
where T: Extract<B>,

Implementors§