1pub type Url2Result<T> = Result<T, Url2Error>;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct Url2Error(Box<Url2ErrorKind>);
7
8impl Url2Error {
9 pub fn kind(&self) -> &Url2ErrorKind {
11 &self.0
12 }
13
14 pub fn into_kind(self) -> Url2ErrorKind {
16 *self.0
17 }
18}
19
20impl std::error::Error for Url2Error {
21 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
22 match *self.0 {
23 Url2ErrorKind::UrlParseError(ref err) => Some(err),
24 }
25 }
26}
27
28impl std::fmt::Display for Url2Error {
29 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
30 match *self.0 {
31 Url2ErrorKind::UrlParseError(ref err) => err.fmt(f),
32 }
33 }
34}
35
36impl std::convert::From<Url2ErrorKind> for Url2Error {
37 fn from(kind: Url2ErrorKind) -> Url2Error {
38 Url2Error(Box::new(kind))
39 }
40}
41
42impl std::convert::From<url::ParseError> for Url2Error {
43 fn from(err: url::ParseError) -> Self {
44 Url2ErrorKind::UrlParseError(err).into()
45 }
46}
47
48#[derive(Debug, Clone, PartialEq, Eq)]
49#[non_exhaustive]
50pub enum Url2ErrorKind {
52 UrlParseError(url::ParseError),
54}