validators 0.21.1

This is a library for validating and modeling user input and this crate provides models, function, traits, errors and other dependencies used with the `validators-derive` crate.
Documentation
use core::fmt::{self, Display, Formatter};

#[cfg(feature = "std")]
use std::error::Error;

use crate::url;

#[derive(Debug)]
pub enum HttpURLError {
    ParseError(url::ParseError),
    // may not be valid but it is guaranteed that the scheme (protocol) is not `http` or `https`
    ProtocolError,
    LocalMust,
    LocalNotAllow,
}

impl From<url::ParseError> for HttpURLError {
    #[inline]
    fn from(error: url::ParseError) -> Self {
        HttpURLError::ParseError(error)
    }
}

impl Display for HttpURLError {
    #[inline]
    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        match self {
            HttpURLError::ParseError(error) => Display::fmt(error, f),
            HttpURLError::ProtocolError => {
                f.write_str("need to use `http` or `https` as a protocol")
            }
            HttpURLError::LocalMust => f.write_str("must be local"),
            HttpURLError::LocalNotAllow => f.write_str("must not be local"),
        }
    }
}

#[cfg(feature = "std")]
impl Error for HttpURLError {}