1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use serde::{Deserialize, Serialize};
use std::{
	borrow::Cow, cmp::Ordering, error::Error, fmt::{self, Display}, net, str::FromStr
};

use super::AmadeusOrd;

#[doc(inline)]
pub use net::{AddrParseError as ParseAddrError, IpAddr};
impl AmadeusOrd for IpAddr {
	fn amadeus_cmp(&self, other: &Self) -> Ordering {
		Ord::cmp(self, other)
	}
}

#[doc(inline)]
pub use url::{ParseError as ParseUrlError, Url};
impl AmadeusOrd for Url {
	fn amadeus_cmp(&self, other: &Self) -> Ordering {
		Ord::cmp(self, other)
	}
}

#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Debug)]
pub struct Webpage<'a> {
	pub ip: IpAddr,
	pub url: Url,
	pub contents: Cow<'a, [u8]>,
}
impl<'a> Webpage<'a> {
	pub fn to_owned(&self) -> Webpage<'static> {
		Webpage {
			ip: self.ip,
			url: self.url.clone(),
			contents: Cow::Owned(self.contents.clone().into_owned()),
		}
	}
}
impl<'a> AmadeusOrd for Webpage<'a> {
	fn amadeus_cmp(&self, other: &Self) -> Ordering {
		Ord::cmp(self, other)
	}
}
impl<'a> Display for Webpage<'a> {
	fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
		unimplemented!()
	}
}
impl<'a> FromStr for Webpage<'a> {
	type Err = ParseWebpageError;

	fn from_str(_s: &str) -> Result<Self, Self::Err> {
		unimplemented!()
	}
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct ParseWebpageError;
impl Display for ParseWebpageError {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		write!(f, "error parsing webpage")
	}
}
impl Error for ParseWebpageError {}