validators/errors/
host.rs

1use core::fmt::{self, Display, Formatter};
2#[cfg(feature = "std")]
3use std::error::Error;
4
5/// Error from the `host` validator.
6#[derive(Debug, Clone)]
7pub enum HostError {
8    /// Incorrect host data.
9    Invalid,
10    /// May not be valid, but it is guaranteed that the domain part is not local.
11    LocalMust,
12    /// May not be valid, but it is guaranteed that the domain part is local.
13    LocalDisallow,
14    /// May not be valid, but it is guaranteed that the domain part has only one label.
15    AtLeastTwoLabelsMust,
16    /// May not be valid, but it is guaranteed that the domain part has at least two labels.
17    AtLeastTwoLabelsDisallow,
18    /// May not be valid, but missing a port is guaranteed.
19    PortMust,
20    /// May not be valid and the port part seems to exist.
21    PortDisallow,
22}
23
24impl Display for HostError {
25    #[inline]
26    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
27        match self {
28            Self::Invalid => f.write_str("invalid domain or IP"),
29            Self::LocalMust => f.write_str("must be local"),
30            Self::LocalDisallow => f.write_str("must not be local"),
31            Self::AtLeastTwoLabelsMust => f.write_str("must have at least two labels"),
32            Self::AtLeastTwoLabelsDisallow => f.write_str("must have only one label"),
33            Self::PortMust => f.write_str("port not found"),
34            Self::PortDisallow => f.write_str("port not allowed"),
35        }
36    }
37}
38
39#[cfg(feature = "std")]
40impl Error for HostError {}