web_url/parse/
error.rs

1use std::fmt::{Display, Formatter};
2
3use crate::parse::Error::*;
4
5/// An error parsing a web-based URL.
6#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
7pub enum Error {
8    /// The scheme was invalid.
9    InvalidScheme,
10
11    /// The host was invalid.
12    InvalidHost,
13
14    /// The port was invalid.
15    InvalidPort,
16
17    /// The path was invalid.
18    InvalidPath,
19
20    /// The query was invalid.
21    InvalidQuery,
22
23    /// The query parameter was invalid.
24    InvalidParam,
25
26    /// The fragment was invalid.
27    InvalidFragment,
28
29    /// The URL was too long. (must be under 4 GiB)
30    UrlTooLong,
31}
32
33impl Error {
34    //! Display
35
36    /// Gets the error message.
37    pub const fn message(&self) -> &'static str {
38        match self {
39            InvalidScheme => "invalid scheme",
40            InvalidHost => "invalid host",
41            InvalidPort => "invalid port",
42            InvalidPath => "invalid path",
43            InvalidQuery => "invalid query",
44            InvalidParam => "invalid query parameter",
45            InvalidFragment => "invalid fragment",
46            UrlTooLong => "URL too long (>= 4 GiB)",
47        }
48    }
49}
50
51impl Display for Error {
52    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
53        write!(f, "{}", self.message())
54    }
55}
56
57impl std::error::Error for Error {}