amadeus_types/
http.rs

1use serde::{Deserialize, Serialize};
2use std::{
3	borrow::Cow, cmp::Ordering, error::Error, fmt::{self, Display}, net, str::FromStr
4};
5
6use super::AmadeusOrd;
7
8#[doc(inline)]
9pub use net::{AddrParseError as ParseAddrError, IpAddr};
10impl AmadeusOrd for IpAddr {
11	fn amadeus_cmp(&self, other: &Self) -> Ordering {
12		Ord::cmp(self, other)
13	}
14}
15
16#[doc(inline)]
17pub use url::{ParseError as ParseUrlError, Url};
18impl AmadeusOrd for Url {
19	fn amadeus_cmp(&self, other: &Self) -> Ordering {
20		Ord::cmp(self, other)
21	}
22}
23
24#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Debug)]
25pub struct Webpage<'a> {
26	pub ip: IpAddr,
27	pub url: Url,
28	pub contents: Cow<'a, [u8]>,
29}
30impl<'a> Webpage<'a> {
31	pub fn to_owned(&self) -> Webpage<'static> {
32		Webpage {
33			ip: self.ip,
34			url: self.url.clone(),
35			contents: Cow::Owned(self.contents.clone().into_owned()),
36		}
37	}
38}
39impl<'a> AmadeusOrd for Webpage<'a> {
40	fn amadeus_cmp(&self, other: &Self) -> Ordering {
41		Ord::cmp(self, other)
42	}
43}
44impl<'a> Display for Webpage<'a> {
45	fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
46		unimplemented!()
47	}
48}
49impl<'a> FromStr for Webpage<'a> {
50	type Err = ParseWebpageError;
51
52	fn from_str(_s: &str) -> Result<Self, Self::Err> {
53		unimplemented!()
54	}
55}
56
57#[derive(Clone, PartialEq, Eq, Debug)]
58pub struct ParseWebpageError;
59impl Display for ParseWebpageError {
60	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61		write!(f, "error parsing webpage")
62	}
63}
64impl Error for ParseWebpageError {}