1use crate::Error::*;
2use std::fmt::{Display, Formatter};
3
4#[non_exhaustive]
6#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
7pub enum Error {
8 InvalidScheme,
10
11 UserInfoNotSupported,
13
14 InvalidHost,
16
17 InvalidPort,
19
20 InvalidPath,
22
23 InvalidQuery,
25
26 InvalidParam,
28
29 InvalidFragment,
31
32 UrlTooLong,
34}
35
36impl Error {
37 #[must_use]
41 pub const fn message(self) -> &'static str {
42 match self {
43 InvalidScheme => "invalid scheme",
44 UserInfoNotSupported => "user info is not supported",
45 InvalidHost => "invalid host",
46 InvalidPort => "invalid port",
47 InvalidPath => "invalid path",
48 InvalidQuery => "invalid query",
49 InvalidParam => "invalid query parameter",
50 InvalidFragment => "invalid fragment",
51 UrlTooLong => "URL too long (>= 4 GiB)",
52 }
53 }
54}
55
56impl Display for Error {
57 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58 f.pad(self.message())
59 }
60}
61
62impl std::error::Error for Error {}