validators/result/mod.rs
1mod built_in_traits;
2#[cfg(feature = "rocket")]
3mod rocket_traits;
4#[cfg(feature = "serde")]
5mod serde_traits;
6
7use core::marker::PhantomData;
8
9/// A wrapper of `core::result::Result`, utilized for specific purposes.
10///
11/// * This struct uses the `FromParam` trait to implement the `FromFormField` trait (only impl the `from_value` method), allowing it to serve as the error type for subsequent checks.
12/// * This struct implements the `Deserialize` trait, allowing it to serve as the error type for subsequent checks.
13#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct Result<T, E, K = ()>(core::result::Result<T, E>, PhantomData<K>);
15
16impl<T, E, K> Result<T, E, K> {
17 /// Create a new instance.
18 #[inline]
19 pub const fn new(result: core::result::Result<T, E>) -> Self {
20 Self(result, PhantomData)
21 }
22
23 /// Convert this instance into `core::result::Result`.
24 #[inline]
25 pub fn into_std_result(self) -> core::result::Result<T, E> {
26 self.0
27 }
28
29 /// Get the reference of the `core::result::Result` instance inside this.
30 #[inline]
31 pub const fn as_std_result(&self) -> &core::result::Result<T, E> {
32 &self.0
33 }
34}