mirror of
				https://github.com/OpenAPITools/openapi-generator.git
				synced 2025-11-04 02:33:54 +00:00 
			
		
		
		
	[Rust-Axum] Fix compilation error when validate is used on Nullable values (#20100)
* Fix compilation error when validate is used on Nullable values * Update samples * Switch Nullable Into Option trait implement to From * Update samples from rebase
This commit is contained in:
		
							parent
							
								
									293524785e
								
							
						
					
					
						commit
						d7a23a9fcf
					
				@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
@ -632,6 +632,131 @@ where
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::Validate for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::Validate,
 | 
			
		||||
{
 | 
			
		||||
    fn validate(&self) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate(),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, T> validator::ValidateArgs<'a> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateArgs<'a>,
 | 
			
		||||
{
 | 
			
		||||
    type Args = T::Args;
 | 
			
		||||
    fn validate_with_args(&self, args: Self::Args) -> Result<(), validator::ValidationErrors> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_with_args(args),
 | 
			
		||||
            Self::Null => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateEmail for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateEmail,
 | 
			
		||||
{
 | 
			
		||||
    fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_email_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateUrl for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateUrl,
 | 
			
		||||
{
 | 
			
		||||
    fn as_url_string(&self) -> Option<std::borrow::Cow<str>> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.as_url_string(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateContains for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateContains,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_contains(&self, needle: &str) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_contains(needle),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRequired for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRequired,
 | 
			
		||||
{
 | 
			
		||||
    fn is_some(&self) -> bool {
 | 
			
		||||
        self.is_present()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> validator::ValidateRegex for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRegex,
 | 
			
		||||
{
 | 
			
		||||
    fn validate_regex(&self, regex: impl validator::AsRegex) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.validate_regex(regex),
 | 
			
		||||
            Self::Null => true,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateRange<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateRange<I>,
 | 
			
		||||
{
 | 
			
		||||
    fn greater_than(&self, max: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.greater_than(max),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn less_than(&self, min: I) -> Option<bool> {
 | 
			
		||||
        use validator::ValidateRange;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.less_than(min),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T, I> validator::ValidateLength<I> for Nullable<T>
 | 
			
		||||
where
 | 
			
		||||
    T: validator::ValidateLength<I>,
 | 
			
		||||
    I: PartialEq + PartialOrd,
 | 
			
		||||
{
 | 
			
		||||
    fn length(&self) -> Option<I> {
 | 
			
		||||
        use validator::ValidateLength;
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Present(x) => x.length(),
 | 
			
		||||
            Self::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> From<Nullable<T>> for Option<T> {
 | 
			
		||||
    fn from(value: Nullable<T>) -> Option<T> {
 | 
			
		||||
        match value {
 | 
			
		||||
            Nullable::Present(x) => Some(x),
 | 
			
		||||
            Nullable::Null => None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[inline(never)]
 | 
			
		||||
#[cold]
 | 
			
		||||
fn expect_failed(msg: &str) -> ! {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user