1use std::fmt::{Display, Formatter};
2
3use crate::parse::Error::*;
4
5#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
7pub enum Error {
8 InvalidScheme,
10
11 InvalidHost,
13
14 InvalidPort,
16
17 InvalidPath,
19
20 InvalidQuery,
22
23 InvalidParam,
25
26 InvalidFragment,
28
29 UrlTooLong,
31}
32
33impl Error {
34 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 {}