Skip to content

Commit 26a0c58

Browse files
committed
feat: remove from_maybe_shared constructors
This also replaces `from_maybe_shared_unchecked` with the new `from_shared_unchecked` constructor. BREAKING CHANGE: the `from_maybe_shared` constructors are removed. Use `TryFrom<Bytes>::try_from` instead.
1 parent d84fed0 commit 26a0c58

File tree

6 files changed

+3
-95
lines changed

6 files changed

+3
-95
lines changed

src/convert.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/header/value.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -172,46 +172,19 @@ impl HeaderValue {
172172
HeaderValue::try_from_generic(src, Bytes::copy_from_slice)
173173
}
174174

175-
/// Attempt to convert a `Bytes` buffer to a `HeaderValue`.
176-
///
177-
/// This will try to prevent a copy if the type passed is the type used
178-
/// internally, and will copy the data if it is not.
179-
pub fn from_maybe_shared<T>(src: T) -> Result<HeaderValue, InvalidHeaderValue>
180-
where
181-
T: AsRef<[u8]> + 'static,
182-
{
183-
if_downcast_into!(T, Bytes, src, {
184-
return HeaderValue::try_from(src);
185-
});
186-
187-
HeaderValue::from_bytes(src.as_ref())
188-
}
189-
190175
/// Convert a `Bytes` directly into a `HeaderValue` without validating.
191176
///
192177
/// This function does NOT validate that illegal bytes are not contained
193178
/// within the buffer.
194-
pub unsafe fn from_maybe_shared_unchecked<T>(src: T) -> HeaderValue
195-
where
196-
T: AsRef<[u8]> + 'static,
197-
{
179+
pub unsafe fn from_shared_unchecked(src: Bytes) -> HeaderValue {
198180
if cfg!(debug_assertions) {
199-
match HeaderValue::from_maybe_shared(src) {
181+
match HeaderValue::try_from(src) {
200182
Ok(val) => val,
201183
Err(_err) => {
202-
panic!("HeaderValue::from_maybe_shared_unchecked() with invalid bytes");
184+
panic!("HeaderValue::from_shared_unchecked() with invalid bytes");
203185
}
204186
}
205187
} else {
206-
207-
if_downcast_into!(T, Bytes, src, {
208-
return HeaderValue {
209-
inner: src,
210-
is_sensitive: false,
211-
};
212-
});
213-
214-
let src = Bytes::copy_from_slice(src.as_ref());
215188
HeaderValue {
216189
inner: src,
217190
is_sensitive: false,

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ extern crate doc_comment;
167167
#[cfg(test)]
168168
doctest!("../README.md");
169169

170-
#[macro_use]
171-
mod convert;
172-
173170
pub mod header;
174171
pub mod method;
175172
pub mod request;

src/uri/authority.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ impl Authority {
4343
.expect("static str is not valid authority")
4444
}
4545

46-
/// Attempt to convert a `Bytes` buffer to a `Authority`.
47-
///
48-
/// This will try to prevent a copy if the type passed is the type used
49-
/// internally, and will copy the data if it is not.
50-
pub fn from_maybe_shared<T>(src: T) -> Result<Self, InvalidUri>
51-
where
52-
T: AsRef<[u8]> + 'static,
53-
{
54-
if_downcast_into!(T, Bytes, src, {
55-
return Authority::try_from(src);
56-
});
57-
58-
Authority::try_from(src.as_ref())
59-
}
60-
6146
// Note: this may return an *empty* Authority. You might want `parse_non_empty`.
6247
// Postcondition: for all Ok() returns, s[..ret.unwrap()] is valid UTF-8 where
6348
// ret is the return value.

src/uri/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,6 @@ impl Uri {
274274
})
275275
}
276276

277-
/// Attempt to convert a `Bytes` buffer to a `Uri`.
278-
///
279-
/// This will try to prevent a copy if the type passed is the type used
280-
/// internally, and will copy the data if it is not.
281-
pub fn from_maybe_shared<T>(src: T) -> Result<Self, InvalidUri>
282-
where
283-
T: AsRef<[u8]> + 'static,
284-
{
285-
if_downcast_into!(T, Bytes, src, {
286-
return Uri::try_from(src);
287-
});
288-
289-
Uri::try_from(src.as_ref())
290-
}
291-
292277
/// Convert a `Uri` from a static string.
293278
///
294279
/// This function will not perform any copying, however the string is

src/uri/path.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,6 @@ impl PathAndQuery {
4242
PathAndQuery::try_from(src).unwrap()
4343
}
4444

45-
/// Attempt to convert a `Bytes` buffer to a `PathAndQuery`.
46-
///
47-
/// This will try to prevent a copy if the type passed is the type used
48-
/// internally, and will copy the data if it is not.
49-
pub fn from_maybe_shared<T>(src: T) -> Result<Self, InvalidUri>
50-
where
51-
T: AsRef<[u8]> + 'static,
52-
{
53-
if_downcast_into!(T, Bytes, src, {
54-
return PathAndQuery::try_from(src);
55-
});
56-
57-
PathAndQuery::try_from(src.as_ref())
58-
}
59-
6045
pub(super) fn empty() -> Self {
6146
PathAndQuery {
6247
data: ByteStr::new(),

0 commit comments

Comments
 (0)