zon_core 0.0.4

part of a new WIP, very incomplete async http service stack
Documentation
use std::{convert::Infallible, future::Future};

use super::RequestParts;
use crate::IntoResponse;

pub trait FromRequestParts: Send + Sized {
    /// If the extractor fails it'll use this "rejection" type. A rejection is
    /// a kind of error that can be converted into a response.
    type Rejection: IntoResponse;

    /// Perform the extraction.
    fn from_request_parts(
        parts: &mut RequestParts,
    ) -> impl Future<Output = Result<Self, Self::Rejection>> + Send;
}

impl FromRequestParts for http::Method {
    type Rejection = Infallible;

    async fn from_request_parts(parts: &mut RequestParts) -> Result<Self, Self::Rejection> {
        Ok(parts.method.clone())
    }
}

impl FromRequestParts for http::Uri {
    type Rejection = Infallible;

    async fn from_request_parts(parts: &mut RequestParts) -> Result<Self, Self::Rejection> {
        Ok(parts.uri.clone())
    }
}

impl<T> FromRequestParts for Result<T, T::Rejection>
where
    T: FromRequestParts,
    T::Rejection: Send,
{
    type Rejection = Infallible;

    async fn from_request_parts(parts: &mut RequestParts) -> Result<Self, Self::Rejection> {
        Ok(T::from_request_parts(parts).await)
    }
}