Skip to content

Commit db9b1b9

Browse files
committed
remove error type variants suffixed with Bytes
We reserved these extra error types with the goal of possibly returning the source `Bytes` in the error type, but no one has since need this. Since the dependency on `bytes` is being made private, it made sense to remove these otherwise unused error types. Removes: - `InvalidUriBytes` - `InvalidHeaderNameBytes` - `InvalidHeaderValueBytes`
1 parent 4ce5e6a commit db9b1b9

File tree

7 files changed

+20
-110
lines changed

7 files changed

+20
-110
lines changed

src/error.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ enum ErrorKind {
2424
StatusCode(status::InvalidStatusCode),
2525
Method(method::InvalidMethod),
2626
Uri(uri::InvalidUri),
27-
UriShared(uri::InvalidUriBytes),
2827
UriParts(uri::InvalidUriParts),
2928
HeaderName(header::InvalidHeaderName),
30-
HeaderNameShared(header::InvalidHeaderNameBytes),
3129
HeaderValue(header::InvalidHeaderValue),
32-
HeaderValueShared(header::InvalidHeaderValueBytes),
3330
}
3431

3532
impl fmt::Debug for Error {
@@ -61,12 +58,9 @@ impl Error {
6158
StatusCode(ref e) => e,
6259
Method(ref e) => e,
6360
Uri(ref e) => e,
64-
UriShared(ref e) => e,
6561
UriParts(ref e) => e,
6662
HeaderName(ref e) => e,
67-
HeaderNameShared(ref e) => e,
6863
HeaderValue(ref e) => e,
69-
HeaderValueShared(ref e) => e,
7064
}
7165
}
7266
}
@@ -79,12 +73,9 @@ impl error::Error for Error {
7973
StatusCode(ref e) => e.description(),
8074
Method(ref e) => e.description(),
8175
Uri(ref e) => e.description(),
82-
UriShared(ref e) => e.description(),
8376
UriParts(ref e) => e.description(),
8477
HeaderName(ref e) => e.description(),
85-
HeaderNameShared(ref e) => e.description(),
8678
HeaderValue(ref e) => e.description(),
87-
HeaderValueShared(ref e) => e.description(),
8879
}
8980
}
9081

@@ -119,14 +110,6 @@ impl From<uri::InvalidUri> for Error {
119110
}
120111
}
121112

122-
impl From<uri::InvalidUriBytes> for Error {
123-
fn from(err: uri::InvalidUriBytes) -> Error {
124-
Error {
125-
inner: ErrorKind::UriShared(err),
126-
}
127-
}
128-
}
129-
130113
impl From<uri::InvalidUriParts> for Error {
131114
fn from(err: uri::InvalidUriParts) -> Error {
132115
Error {
@@ -143,14 +126,6 @@ impl From<header::InvalidHeaderName> for Error {
143126
}
144127
}
145128

146-
impl From<header::InvalidHeaderNameBytes> for Error {
147-
fn from(err: header::InvalidHeaderNameBytes) -> Error {
148-
Error {
149-
inner: ErrorKind::HeaderNameShared(err),
150-
}
151-
}
152-
}
153-
154129
impl From<header::InvalidHeaderValue> for Error {
155130
fn from(err: header::InvalidHeaderValue) -> Error {
156131
Error {
@@ -159,14 +134,6 @@ impl From<header::InvalidHeaderValue> for Error {
159134
}
160135
}
161136

162-
impl From<header::InvalidHeaderValueBytes> for Error {
163-
fn from(err: header::InvalidHeaderValueBytes) -> Error {
164-
Error {
165-
inner: ErrorKind::HeaderValueShared(err),
166-
}
167-
}
168-
}
169-
170137
impl From<std::convert::Infallible> for Error {
171138
fn from(err: std::convert::Infallible) -> Error {
172139
match err {}

src/header/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ pub use self::map::{
7878
AsHeaderName, Drain, Entry, GetAll, HeaderMap, IntoHeaderName, IntoIter, Iter, IterMut, Keys,
7979
OccupiedEntry, VacantEntry, ValueDrain, ValueIter, ValueIterMut, Values, ValuesMut,
8080
};
81-
pub use self::name::{HeaderName, InvalidHeaderName, InvalidHeaderNameBytes};
82-
pub use self::value::{HeaderValue, InvalidHeaderValue, InvalidHeaderValueBytes, ToStrError};
81+
pub use self::name::{HeaderName, InvalidHeaderName};
82+
pub use self::value::{HeaderValue, InvalidHeaderValue, ToStrError};
8383

8484
// Use header name constants
8585
pub use self::name::{

src/header/name.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ pub struct InvalidHeaderName {
6060
_priv: (),
6161
}
6262

63-
/// A possible error when converting a `HeaderName` from another type.
64-
#[derive(Debug)]
65-
pub struct InvalidHeaderNameBytes(InvalidHeaderName);
66-
6763
macro_rules! standard_headers {
6864
(
6965
$(
@@ -2017,18 +2013,6 @@ impl Error for InvalidHeaderName {
20172013
}
20182014
}
20192015

2020-
impl fmt::Display for InvalidHeaderNameBytes {
2021-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2022-
self.0.fmt(f)
2023-
}
2024-
}
2025-
2026-
impl Error for InvalidHeaderNameBytes {
2027-
fn description(&self) -> &str {
2028-
self.0.description()
2029-
}
2030-
}
2031-
20322016
// ===== HdrName =====
20332017

20342018
impl<'a> HdrName<'a> {

src/header/value.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ pub struct InvalidHeaderValue {
2828
_priv: (),
2929
}
3030

31-
/// A possible error when converting a `HeaderValue` from a string or byte
32-
/// slice.
33-
#[derive(Debug)]
34-
pub struct InvalidHeaderValueBytes(InvalidHeaderValue);
35-
3631
/// A possible error when converting a `HeaderValue` to a string representation.
3732
///
3833
/// Header field values may contain opaque bytes, in which case it is not
@@ -161,8 +156,8 @@ impl HeaderValue {
161156
/// This function is intended to be replaced in the future by a `TryFrom`
162157
/// implementation once the trait is stabilized in std.
163158
#[inline]
164-
fn from_shared(src: Bytes) -> Result<HeaderValue, InvalidHeaderValueBytes> {
165-
HeaderValue::try_from_generic(src, std::convert::identity).map_err(InvalidHeaderValueBytes)
159+
fn from_shared(src: Bytes) -> Result<HeaderValue, InvalidHeaderValue> {
160+
HeaderValue::try_from_generic(src, std::convert::identity)
166161
}
167162

168163
/*
@@ -176,8 +171,6 @@ impl HeaderValue {
176171
match HeaderValue::from_shared(src) {
177172
Ok(val) => val,
178173
Err(_err) => {
179-
//TODO: if the Bytes were part of the InvalidHeaderValueBytes,
180-
//this message could include the invalid bytes.
181174
panic!("HeaderValue::from_shared_unchecked() with invalid bytes");
182175
}
183176
}
@@ -511,7 +504,7 @@ impl<'a> TryFrom<&'a [u8]> for HeaderValue {
511504
}
512505

513506
impl TryFrom<String> for HeaderValue {
514-
type Error = InvalidHeaderValueBytes;
507+
type Error = InvalidHeaderValue;
515508

516509
#[inline]
517510
fn try_from(t: String) -> Result<Self, Self::Error> {
@@ -520,7 +513,7 @@ impl TryFrom<String> for HeaderValue {
520513
}
521514

522515
impl TryFrom<Vec<u8>> for HeaderValue {
523-
type Error = InvalidHeaderValueBytes;
516+
type Error = InvalidHeaderValue;
524517

525518
#[inline]
526519
fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error> {
@@ -571,18 +564,6 @@ impl Error for InvalidHeaderValue {
571564
}
572565
}
573566

574-
impl fmt::Display for InvalidHeaderValueBytes {
575-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
576-
self.0.fmt(f)
577-
}
578-
}
579-
580-
impl Error for InvalidHeaderValueBytes {
581-
fn description(&self) -> &str {
582-
self.0.description()
583-
}
584-
}
585-
586567
impl fmt::Display for ToStrError {
587568
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
588569
self.description().fmt(f)

src/uri/authority.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{cmp, fmt, str};
55

66
use bytes::Bytes;
77

8-
use super::{ErrorKind, InvalidUri, InvalidUriBytes, Port, URI_CHARS};
8+
use super::{ErrorKind, InvalidUri, Port, URI_CHARS};
99
use crate::byte_str::ByteStr;
1010

1111
/// Represents the authority component of a URI.
@@ -41,8 +41,8 @@ impl Authority {
4141
/// assert_eq!(authority.host(), "example.com");
4242
/// # }
4343
/// ```
44-
pub(super) fn from_shared(s: Bytes) -> Result<Self, InvalidUriBytes> {
45-
let authority_end = Authority::parse_non_empty(&s[..]).map_err(InvalidUriBytes)?;
44+
pub(super) fn from_shared(s: Bytes) -> Result<Self, InvalidUri> {
45+
let authority_end = Authority::parse_non_empty(&s[..])?;
4646

4747
if authority_end != s.len() {
4848
return Err(ErrorKind::InvalidUriChar.into());
@@ -269,7 +269,7 @@ impl Authority {
269269

270270
/*
271271
impl TryFrom<Bytes> for Authority {
272-
type Error = InvalidUriBytes;
272+
type Error = InvalidUri;
273273
/// Attempt to convert an `Authority` from `Bytes`.
274274
///
275275
/// # Examples
@@ -290,7 +290,7 @@ impl TryFrom<Bytes> for Authority {
290290
/// # }
291291
/// ```
292292
fn try_from(s: Bytes) -> Result<Self, Self::Error> {
293-
let authority_end = Authority::parse_non_empty(&s[..]).map_err(InvalidUriBytes)?;
293+
let authority_end = Authority::parse_non_empty(&s[..])?;
294294
295295
if authority_end != s.len() {
296296
return Err(ErrorKind::InvalidUriChar.into());

src/uri/mod.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ pub struct Parts {
121121
#[derive(Debug)]
122122
pub struct InvalidUri(ErrorKind);
123123

124-
/// An error resulting from a failed attempt to construct a URI.
125-
#[derive(Debug)]
126-
pub struct InvalidUriBytes(InvalidUri);
127-
128124
/// An error resulting from a failed attempt to construct a URI.
129125
#[derive(Debug)]
130126
pub struct InvalidUriParts(InvalidUri);
@@ -260,7 +256,7 @@ impl Uri {
260256
/// assert_eq!(uri.path(), "/foo");
261257
/// # }
262258
/// ```
263-
fn from_shared(s: Bytes) -> Result<Uri, InvalidUriBytes> {
259+
fn from_shared(s: Bytes) -> Result<Uri, InvalidUri> {
264260
use self::ErrorKind::*;
265261

266262
if s.len() > MAX_LEN {
@@ -697,7 +693,7 @@ impl<'a> TryFrom<&'a String> for Uri {
697693
}
698694

699695
impl TryFrom<String> for Uri {
700-
type Error = InvalidUriBytes;
696+
type Error = InvalidUri;
701697

702698
#[inline]
703699
fn try_from(t: String) -> Result<Self, Self::Error> {
@@ -785,9 +781,9 @@ impl From<Uri> for Parts {
785781
}
786782
}
787783

788-
fn parse_full(mut s: Bytes) -> Result<Uri, InvalidUriBytes> {
784+
fn parse_full(mut s: Bytes) -> Result<Uri, InvalidUri> {
789785
// Parse the scheme
790-
let scheme = match Scheme2::parse(&s[..]).map_err(InvalidUriBytes)? {
786+
let scheme = match Scheme2::parse(&s[..])? {
791787
Scheme2::None => Scheme2::None,
792788
Scheme2::Standard(p) => {
793789
// TODO: use truncate
@@ -810,7 +806,7 @@ fn parse_full(mut s: Bytes) -> Result<Uri, InvalidUriBytes> {
810806

811807
// Find the end of the authority. The scheme will already have been
812808
// extracted.
813-
let authority_end = Authority::parse(&s[..]).map_err(InvalidUriBytes)?;
809+
let authority_end = Authority::parse(&s[..])?;
814810

815811
if scheme.is_none() {
816812
if authority_end != s.len() {
@@ -850,7 +846,7 @@ impl FromStr for Uri {
850846

851847
#[inline]
852848
fn from_str(s: &str) -> Result<Uri, InvalidUri> {
853-
Uri::from_shared(Bytes::copy_from_slice(s.as_bytes())).map_err(|e| e.0)
849+
Uri::from_shared(Bytes::copy_from_slice(s.as_bytes()))
854850
}
855851
}
856852

@@ -1019,12 +1015,6 @@ impl From<ErrorKind> for InvalidUri {
10191015
}
10201016
}
10211017

1022-
impl From<ErrorKind> for InvalidUriBytes {
1023-
fn from(src: ErrorKind) -> InvalidUriBytes {
1024-
InvalidUriBytes(src.into())
1025-
}
1026-
}
1027-
10281018
impl From<ErrorKind> for InvalidUriParts {
10291019
fn from(src: ErrorKind) -> InvalidUriParts {
10301020
InvalidUriParts(src.into())
@@ -1055,24 +1045,12 @@ impl Error for InvalidUri {
10551045
}
10561046
}
10571047

1058-
impl fmt::Display for InvalidUriBytes {
1059-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1060-
self.0.fmt(f)
1061-
}
1062-
}
1063-
10641048
impl fmt::Display for InvalidUriParts {
10651049
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10661050
self.0.fmt(f)
10671051
}
10681052
}
10691053

1070-
impl Error for InvalidUriBytes {
1071-
fn description(&self) -> &str {
1072-
self.0.description()
1073-
}
1074-
}
1075-
10761054
impl Error for InvalidUriParts {
10771055
fn description(&self) -> &str {
10781056
self.0.description()

src/uri/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{cmp, fmt, str};
44

55
use bytes::Bytes;
66

7-
use super::{ErrorKind, InvalidUri, InvalidUriBytes};
7+
use super::{ErrorKind, InvalidUri};
88
use crate::byte_str::ByteStr;
99

1010
/// Represents the path component of a URI
@@ -39,7 +39,7 @@ impl PathAndQuery {
3939
/// assert_eq!(path_and_query.query(), Some("world"));
4040
/// # }
4141
/// ```
42-
pub(super) fn from_shared(mut src: Bytes) -> Result<Self, InvalidUriBytes> {
42+
pub(super) fn from_shared(mut src: Bytes) -> Result<Self, InvalidUri> {
4343
let mut query = NONE;
4444
let mut fragment = None;
4545

@@ -281,7 +281,7 @@ impl<'a> TryFrom<&'a [u8]> for PathAndQuery {
281281
type Error = InvalidUri;
282282
#[inline]
283283
fn try_from(s: &'a [u8]) -> Result<Self, Self::Error> {
284-
PathAndQuery::from_shared(Bytes::copy_from_slice(s)).map_err(|e| e.0)
284+
PathAndQuery::from_shared(Bytes::copy_from_slice(s))
285285
}
286286
}
287287

0 commit comments

Comments
 (0)