argan-core 0.1.1

Core types and traits for the Argan Web Framework.
Documentation
//! Request types and conversion trait for data extractors.

// ----------

use std::future::{ready, Future};

use crate::{body::Body, response::BoxedErrorResponse};

// ----------

pub use http::request::Builder;

// --------------------------------------------------

mod impls;

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

pub type Request<B = Body> = http::request::Request<B>;
pub type RequestHeadParts = http::request::Parts;

// --------------------------------------------------
// FromRequest<B>

/// A trait for extractor types.
///
/// Implementors of the `FromRequest` consume the request body and usually convert it
/// to some form of data.
pub trait FromRequest<B = Body>: Sized {
	type Error: Into<BoxedErrorResponse>;

	fn from_request(
		head_parts: &mut RequestHeadParts,
		body: B,
	) -> impl Future<Output = Result<Self, Self::Error>> + Send;
}

// --------------------------------------------------------------------------------