argan_core/request/
impls.rs

1use std::convert::Infallible;
2
3use futures_util::FutureExt;
4
5use super::*;
6
7// --------------------------------------------------------------------------------
8// --------------------------------------------------------------------------------
9
10// --------------------------------------------------
11// Result<T, E>
12
13impl<B, T, E> FromRequest<B> for Result<T, E>
14where
15	T: FromRequest<B, Error = E>,
16{
17	type Error = Infallible;
18
19	fn from_request(
20		head_parts: &mut RequestHeadParts,
21		body: B,
22	) -> impl Future<Output = Result<Self, Self::Error>> {
23		T::from_request(head_parts, body).map(Ok)
24	}
25}
26
27// --------------------------------------------------
28// Option<T>
29
30impl<B, T> FromRequest<B> for Option<T>
31where
32	T: FromRequest<B>,
33{
34	type Error = Infallible;
35
36	fn from_request(
37		head_parts: &mut RequestHeadParts,
38		body: B,
39	) -> impl Future<Output = Result<Self, Self::Error>> {
40		T::from_request(head_parts, body).map(|result| Ok(result.ok()))
41	}
42}
43
44// --------------------------------------------------
45// ()
46
47impl<B> FromRequest<B> for () {
48	type Error = Infallible;
49
50	fn from_request(
51		_head_parts: &mut RequestHeadParts,
52		_: B,
53	) -> impl Future<Output = Result<Self, Self::Error>> + Send {
54		ready(Ok(()))
55	}
56}
57
58// --------------------------------------------------------------------------------