1use url::{Url, ParseError};
2
3use Error;
4use header::{HeaderName, HeaderValue};
5use method::Method;
6use sealed::Sealed;
7use status::StatusCode;
8
9pub trait HttpTryFrom<T>: Sized + Sealed {
19 type Error: Into<Error>;
21
22 #[doc(hidden)]
23 fn try_from(t: T) -> Result<Self, Self::Error>;
24}
25
26macro_rules! reflexive {
27 ($($t:ty,)*) => ($(
28 impl HttpTryFrom<$t> for $t {
29 type Error = Error;
30
31 fn try_from(t: Self) -> Result<Self, Self::Error> {
32 Ok(t)
33 }
34 }
35
36 impl Sealed for $t {}
37 )*)
38}
39
40reflexive! {
41 Url,
42 Method,
43 StatusCode,
44 HeaderName,
45 HeaderValue,
46}
47
48impl<'a> HttpTryFrom<&'a str> for Url {
49 type Error = ParseError;
50
51 fn try_from(input: &str) -> Result<Url, ParseError> {
52 Url::parse(input)
53 }
54}