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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
use std::convert::TryFrom;
use std::borrow::Borrow;
use crate::imp;
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[repr(transparent)]
pub struct HeaderName(imp::HeaderName);
impl<'a> TryFrom<&'a str> for HeaderName {
type Error = imp::Error;
#[inline]
fn try_from(t: &'a str) -> Result<HeaderName, Self::Error> {
#[cfg(feature = "use_async_h1")]
return Ok(HeaderName(imp::HeaderName::from_string(t.to_string())?));
#[cfg(feature = "use_hyper")]
return Ok(HeaderName(imp::HeaderName::try_from(t)?));
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return Err(imp::Error{})
}
}
impl<'a> TryFrom<&'a [u8]> for HeaderName {
type Error = imp::Error;
#[inline]
fn try_from(t: &'a [u8]) -> Result<Self, Self::Error> {
#[cfg(feature = "use_async_h1")]
return Ok(HeaderName(imp::HeaderName::from_bytes(t.to_vec())?));
#[cfg(feature = "use_hyper")]
return Ok(HeaderName(imp::HeaderName::from_bytes(t)?));
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return Err(imp::Error{})
}
}
impl TryFrom<Vec<u8>> for HeaderName {
type Error = imp::Error;
#[inline]
fn try_from(t: Vec<u8>) -> Result<Self, Self::Error> {
#[cfg(feature = "use_async_h1")]
return Ok(HeaderName(imp::HeaderName::from_bytes(t)?));
#[cfg(feature = "use_hyper")]
return Ok(HeaderName(imp::HeaderName::from_bytes(&t)?));
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return Err(imp::Error{})
}
}
impl From<HeaderName> for imp::HeaderName {
#[inline]
fn from(t: HeaderName) -> Self {
t.0
}
}
impl<'a> From<&'a imp::HeaderName> for &'a HeaderName {
#[inline]
fn from(t: &'a imp::HeaderName) -> Self {
unsafe{std::mem::transmute(t)}
}
}
impl AsRef<str> for HeaderName {
#[inline]
fn as_ref(&self) -> &str {
#[cfg(feature = "use_hyper")]
return self.0.as_ref();
#[cfg(feature = "use_async_h1")]
return self.0.as_str();
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return "";
}
}
impl AsRef<[u8]> for HeaderName {
#[inline]
fn as_ref(&self) -> &[u8] {
#[cfg(feature = "use_hyper")]
return self.0.as_ref();
#[cfg(feature = "use_async_h1")]
return self.0.as_str().as_bytes();
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return &[];
}
}
impl Borrow<str> for HeaderName {
#[inline]
fn borrow(&self) -> &str {
#[cfg(feature = "use_hyper")]
return self.as_ref();
#[cfg(feature = "use_async_h1")]
return self.0.as_str();
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return "";
}
}
impl PartialEq<str> for HeaderName {
#[inline]
fn eq(&self, other: &str) -> bool {
#[cfg(feature = "use_hyper")]
return self.0 == other;
#[cfg(feature = "use_async_h1")]
return self.0.as_str() == other;
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return false;
}
}
#[derive(Debug)]
#[repr(transparent)]
pub struct HeaderValue(imp::HeaderValue);
impl<'a> TryFrom<&'a str> for HeaderValue {
type Error = imp::Error;
#[inline]
fn try_from(t: &'a str) -> Result<Self, Self::Error> {
Ok(HeaderValue(imp::HeaderValue::try_from(t)?))
}
}
impl<'a> TryFrom<&'a [u8]> for HeaderValue {
type Error = imp::Error;
#[inline]
fn try_from(t: &'a [u8]) -> Result<Self, Self::Error> {
#[cfg(feature = "use_async_h1")]
return Ok(HeaderValue(imp::HeaderValue::from_bytes(t.to_vec())?));
#[cfg(feature = "use_hyper")]
return Ok(HeaderValue(imp::HeaderValue::from_bytes(t)?));
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return Err(imp::Error{})
}
}
impl From<HeaderValue> for imp::HeaderValue {
#[inline]
fn from(t: HeaderValue) -> Self {
t.0
}
}
impl From<imp::HeaderValue> for HeaderValue {
#[inline]
fn from(t: imp::HeaderValue) -> Self {
HeaderValue(t)
}
}
impl<'a> From<&'a imp::HeaderValue> for &'a HeaderValue {
#[inline]
fn from(t: &'a imp::HeaderValue) -> Self {
unsafe{std::mem::transmute(t)}
}
}
impl AsRef<[u8]> for HeaderValue {
#[inline]
fn as_ref(&self) -> &[u8] {
#[cfg(feature = "use_hyper")]
return self.0.as_ref();
#[cfg(feature = "use_async_h1")]
return self.0.as_str().as_bytes();
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return &[];
}
}
impl std::convert::TryInto<String> for HeaderValue {
type Error = std::string::FromUtf8Error;
fn try_into(self) -> Result<String, Self::Error> {
#[cfg(feature = "use_async_h1")]
return Ok(self.0.as_str().to_string());
String::from_utf8(self.as_ref().to_vec())
}
}
impl std::convert::TryInto<String> for &HeaderValue {
type Error = std::string::FromUtf8Error;
fn try_into(self) -> Result<String, Self::Error> {
#[cfg(feature = "use_async_h1")]
return Ok(self.0.as_str().to_string());
String::from_utf8(self.as_ref().to_vec())
}
}
impl PartialEq<str> for HeaderValue {
#[inline]
fn eq(&self, other: &str) -> bool {
#[cfg(feature = "use_hyper")]
return self.0 == other.as_bytes();
#[cfg(feature = "use_async_h1")]
return self.0.as_str() == other;
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return false;
}
}
impl PartialEq<[u8]> for HeaderValue {
#[inline]
fn eq(&self, other: &[u8]) -> bool {
#[cfg(feature = "use_hyper")]
return self.0 == other;
#[cfg(feature = "use_async_h1")]
return self.as_ref() == other;
#[cfg(not(any(feature = "use_hyper", feature = "use_async_h1")))]
return false;
}
}