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`
This commit is contained in:
Sean McArthur
2019-12-02 10:54:22 -08:00
parent bcccb669a4
commit 11efef0cb0
7 changed files with 20 additions and 110 deletions
-33
View File
@@ -24,12 +24,9 @@ enum ErrorKind {
StatusCode(status::InvalidStatusCode),
Method(method::InvalidMethod),
Uri(uri::InvalidUri),
UriShared(uri::InvalidUriBytes),
UriParts(uri::InvalidUriParts),
HeaderName(header::InvalidHeaderName),
HeaderNameShared(header::InvalidHeaderNameBytes),
HeaderValue(header::InvalidHeaderValue),
HeaderValueShared(header::InvalidHeaderValueBytes),
}
impl fmt::Debug for Error {
@@ -61,12 +58,9 @@ impl Error {
StatusCode(ref e) => e,
Method(ref e) => e,
Uri(ref e) => e,
UriShared(ref e) => e,
UriParts(ref e) => e,
HeaderName(ref e) => e,
HeaderNameShared(ref e) => e,
HeaderValue(ref e) => e,
HeaderValueShared(ref e) => e,
}
}
}
@@ -79,12 +73,9 @@ impl error::Error for Error {
StatusCode(ref e) => e.description(),
Method(ref e) => e.description(),
Uri(ref e) => e.description(),
UriShared(ref e) => e.description(),
UriParts(ref e) => e.description(),
HeaderName(ref e) => e.description(),
HeaderNameShared(ref e) => e.description(),
HeaderValue(ref e) => e.description(),
HeaderValueShared(ref e) => e.description(),
}
}
@@ -119,14 +110,6 @@ impl From<uri::InvalidUri> for Error {
}
}
impl From<uri::InvalidUriBytes> for Error {
fn from(err: uri::InvalidUriBytes) -> Error {
Error {
inner: ErrorKind::UriShared(err),
}
}
}
impl From<uri::InvalidUriParts> for Error {
fn from(err: uri::InvalidUriParts) -> Error {
Error {
@@ -143,14 +126,6 @@ impl From<header::InvalidHeaderName> for Error {
}
}
impl From<header::InvalidHeaderNameBytes> for Error {
fn from(err: header::InvalidHeaderNameBytes) -> Error {
Error {
inner: ErrorKind::HeaderNameShared(err),
}
}
}
impl From<header::InvalidHeaderValue> for Error {
fn from(err: header::InvalidHeaderValue) -> Error {
Error {
@@ -159,14 +134,6 @@ impl From<header::InvalidHeaderValue> for Error {
}
}
impl From<header::InvalidHeaderValueBytes> for Error {
fn from(err: header::InvalidHeaderValueBytes) -> Error {
Error {
inner: ErrorKind::HeaderValueShared(err),
}
}
}
impl From<std::convert::Infallible> for Error {
fn from(err: std::convert::Infallible) -> Error {
match err {}
+2 -2
View File
@@ -78,8 +78,8 @@ pub use self::map::{
AsHeaderName, Drain, Entry, GetAll, HeaderMap, IntoHeaderName, IntoIter, Iter, IterMut, Keys,
OccupiedEntry, VacantEntry, ValueDrain, ValueIter, ValueIterMut, Values, ValuesMut,
};
pub use self::name::{HeaderName, InvalidHeaderName, InvalidHeaderNameBytes};
pub use self::value::{HeaderValue, InvalidHeaderValue, InvalidHeaderValueBytes, ToStrError};
pub use self::name::{HeaderName, InvalidHeaderName};
pub use self::value::{HeaderValue, InvalidHeaderValue, ToStrError};
// Use header name constants
pub use self::name::{
-16
View File
@@ -60,10 +60,6 @@ pub struct InvalidHeaderName {
_priv: (),
}
/// A possible error when converting a `HeaderName` from another type.
#[derive(Debug)]
pub struct InvalidHeaderNameBytes(InvalidHeaderName);
macro_rules! standard_headers {
(
$(
@@ -2017,18 +2013,6 @@ impl Error for InvalidHeaderName {
}
}
impl fmt::Display for InvalidHeaderNameBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl Error for InvalidHeaderNameBytes {
fn description(&self) -> &str {
self.0.description()
}
}
// ===== HdrName =====
impl<'a> HdrName<'a> {
+4 -23
View File
@@ -28,11 +28,6 @@ pub struct InvalidHeaderValue {
_priv: (),
}
/// A possible error when converting a `HeaderValue` from a string or byte
/// slice.
#[derive(Debug)]
pub struct InvalidHeaderValueBytes(InvalidHeaderValue);
/// A possible error when converting a `HeaderValue` to a string representation.
///
/// Header field values may contain opaque bytes, in which case it is not
@@ -161,8 +156,8 @@ impl HeaderValue {
/// This function is intended to be replaced in the future by a `TryFrom`
/// implementation once the trait is stabilized in std.
#[inline]
fn from_shared(src: Bytes) -> Result<HeaderValue, InvalidHeaderValueBytes> {
HeaderValue::try_from_generic(src, std::convert::identity).map_err(InvalidHeaderValueBytes)
fn from_shared(src: Bytes) -> Result<HeaderValue, InvalidHeaderValue> {
HeaderValue::try_from_generic(src, std::convert::identity)
}
/*
@@ -176,8 +171,6 @@ impl HeaderValue {
match HeaderValue::from_shared(src) {
Ok(val) => val,
Err(_err) => {
//TODO: if the Bytes were part of the InvalidHeaderValueBytes,
//this message could include the invalid bytes.
panic!("HeaderValue::from_shared_unchecked() with invalid bytes");
}
}
@@ -511,7 +504,7 @@ impl<'a> TryFrom<&'a [u8]> for HeaderValue {
}
impl TryFrom<String> for HeaderValue {
type Error = InvalidHeaderValueBytes;
type Error = InvalidHeaderValue;
#[inline]
fn try_from(t: String) -> Result<Self, Self::Error> {
@@ -520,7 +513,7 @@ impl TryFrom<String> for HeaderValue {
}
impl TryFrom<Vec<u8>> for HeaderValue {
type Error = InvalidHeaderValueBytes;
type Error = InvalidHeaderValue;
#[inline]
fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error> {
@@ -571,18 +564,6 @@ impl Error for InvalidHeaderValue {
}
}
impl fmt::Display for InvalidHeaderValueBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl Error for InvalidHeaderValueBytes {
fn description(&self) -> &str {
self.0.description()
}
}
impl fmt::Display for ToStrError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.description().fmt(f)
+5 -5
View File
@@ -5,7 +5,7 @@ use std::{cmp, fmt, str};
use bytes::Bytes;
use super::{ErrorKind, InvalidUri, InvalidUriBytes, Port, URI_CHARS};
use super::{ErrorKind, InvalidUri, Port, URI_CHARS};
use crate::byte_str::ByteStr;
/// Represents the authority component of a URI.
@@ -41,8 +41,8 @@ impl Authority {
/// assert_eq!(authority.host(), "example.com");
/// # }
/// ```
pub(super) fn from_shared(s: Bytes) -> Result<Self, InvalidUriBytes> {
let authority_end = Authority::parse_non_empty(&s[..]).map_err(InvalidUriBytes)?;
pub(super) fn from_shared(s: Bytes) -> Result<Self, InvalidUri> {
let authority_end = Authority::parse_non_empty(&s[..])?;
if authority_end != s.len() {
return Err(ErrorKind::InvalidUriChar.into());
@@ -269,7 +269,7 @@ impl Authority {
/*
impl TryFrom<Bytes> for Authority {
type Error = InvalidUriBytes;
type Error = InvalidUri;
/// Attempt to convert an `Authority` from `Bytes`.
///
/// # Examples
@@ -290,7 +290,7 @@ impl TryFrom<Bytes> for Authority {
/// # }
/// ```
fn try_from(s: Bytes) -> Result<Self, Self::Error> {
let authority_end = Authority::parse_non_empty(&s[..]).map_err(InvalidUriBytes)?;
let authority_end = Authority::parse_non_empty(&s[..])?;
if authority_end != s.len() {
return Err(ErrorKind::InvalidUriChar.into());
+6 -28
View File
@@ -121,10 +121,6 @@ pub struct Parts {
#[derive(Debug)]
pub struct InvalidUri(ErrorKind);
/// An error resulting from a failed attempt to construct a URI.
#[derive(Debug)]
pub struct InvalidUriBytes(InvalidUri);
/// An error resulting from a failed attempt to construct a URI.
#[derive(Debug)]
pub struct InvalidUriParts(InvalidUri);
@@ -260,7 +256,7 @@ impl Uri {
/// assert_eq!(uri.path(), "/foo");
/// # }
/// ```
fn from_shared(s: Bytes) -> Result<Uri, InvalidUriBytes> {
fn from_shared(s: Bytes) -> Result<Uri, InvalidUri> {
use self::ErrorKind::*;
if s.len() > MAX_LEN {
@@ -697,7 +693,7 @@ impl<'a> TryFrom<&'a String> for Uri {
}
impl TryFrom<String> for Uri {
type Error = InvalidUriBytes;
type Error = InvalidUri;
#[inline]
fn try_from(t: String) -> Result<Self, Self::Error> {
@@ -785,9 +781,9 @@ impl From<Uri> for Parts {
}
}
fn parse_full(mut s: Bytes) -> Result<Uri, InvalidUriBytes> {
fn parse_full(mut s: Bytes) -> Result<Uri, InvalidUri> {
// Parse the scheme
let scheme = match Scheme2::parse(&s[..]).map_err(InvalidUriBytes)? {
let scheme = match Scheme2::parse(&s[..])? {
Scheme2::None => Scheme2::None,
Scheme2::Standard(p) => {
// TODO: use truncate
@@ -810,7 +806,7 @@ fn parse_full(mut s: Bytes) -> Result<Uri, InvalidUriBytes> {
// Find the end of the authority. The scheme will already have been
// extracted.
let authority_end = Authority::parse(&s[..]).map_err(InvalidUriBytes)?;
let authority_end = Authority::parse(&s[..])?;
if scheme.is_none() {
if authority_end != s.len() {
@@ -850,7 +846,7 @@ impl FromStr for Uri {
#[inline]
fn from_str(s: &str) -> Result<Uri, InvalidUri> {
Uri::from_shared(Bytes::copy_from_slice(s.as_bytes())).map_err(|e| e.0)
Uri::from_shared(Bytes::copy_from_slice(s.as_bytes()))
}
}
@@ -1019,12 +1015,6 @@ impl From<ErrorKind> for InvalidUri {
}
}
impl From<ErrorKind> for InvalidUriBytes {
fn from(src: ErrorKind) -> InvalidUriBytes {
InvalidUriBytes(src.into())
}
}
impl From<ErrorKind> for InvalidUriParts {
fn from(src: ErrorKind) -> InvalidUriParts {
InvalidUriParts(src.into())
@@ -1055,24 +1045,12 @@ impl Error for InvalidUri {
}
}
impl fmt::Display for InvalidUriBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Display for InvalidUriParts {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl Error for InvalidUriBytes {
fn description(&self) -> &str {
self.0.description()
}
}
impl Error for InvalidUriParts {
fn description(&self) -> &str {
self.0.description()
+3 -3
View File
@@ -4,7 +4,7 @@ use std::{cmp, fmt, str};
use bytes::Bytes;
use super::{ErrorKind, InvalidUri, InvalidUriBytes};
use super::{ErrorKind, InvalidUri};
use crate::byte_str::ByteStr;
/// Represents the path component of a URI
@@ -39,7 +39,7 @@ impl PathAndQuery {
/// assert_eq!(path_and_query.query(), Some("world"));
/// # }
/// ```
pub(super) fn from_shared(mut src: Bytes) -> Result<Self, InvalidUriBytes> {
pub(super) fn from_shared(mut src: Bytes) -> Result<Self, InvalidUri> {
let mut query = NONE;
let mut fragment = None;
@@ -281,7 +281,7 @@ impl<'a> TryFrom<&'a [u8]> for PathAndQuery {
type Error = InvalidUri;
#[inline]
fn try_from(s: &'a [u8]) -> Result<Self, Self::Error> {
PathAndQuery::from_shared(Bytes::copy_from_slice(s)).map_err(|e| e.0)
PathAndQuery::from_shared(Bytes::copy_from_slice(s))
}
}