pub(crate)ify the error module
This commit is contained in:
27
src/error.rs
27
src/error.rs
@@ -253,7 +253,7 @@ impl StdError for Error {
|
|||||||
// pub(crate)
|
// pub(crate)
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Kind {
|
pub(crate) enum Kind {
|
||||||
Http(::http::Error),
|
Http(::http::Error),
|
||||||
Hyper(::hyper::Error),
|
Hyper(::hyper::Error),
|
||||||
Mime(::mime::FromStrError),
|
Mime(::mime::FromStrError),
|
||||||
@@ -344,10 +344,8 @@ fn io_timeout() -> io::Error {
|
|||||||
io::Error::new(io::ErrorKind::TimedOut, "timed out")
|
io::Error::new(io::ErrorKind::TimedOut, "timed out")
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub(crate)
|
|
||||||
|
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct InternalFrom<T>(pub T, pub Option<Url>);
|
pub(crate) struct InternalFrom<T>(pub T, pub Option<Url>);
|
||||||
|
|
||||||
#[doc(hidden)] // https://github.com/rust-lang/rust/issues/42323
|
#[doc(hidden)] // https://github.com/rust-lang/rust/issues/42323
|
||||||
impl From<InternalFrom<Error>> for Error {
|
impl From<InternalFrom<Error>> for Error {
|
||||||
@@ -371,16 +369,14 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub(crate) fn from<T>(err: T) -> Error
|
||||||
pub fn from<T>(err: T) -> Error
|
|
||||||
where
|
where
|
||||||
T: Into<Kind>,
|
T: Into<Kind>,
|
||||||
{
|
{
|
||||||
InternalFrom(err, None).into()
|
InternalFrom(err, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub(crate) fn into_io(e: Error) -> io::Error {
|
||||||
pub fn into_io(e: Error) -> io::Error {
|
|
||||||
match e.kind {
|
match e.kind {
|
||||||
Kind::Io(io) => io,
|
Kind::Io(io) => io,
|
||||||
_ => io::Error::new(io::ErrorKind::Other, e),
|
_ => io::Error::new(io::ErrorKind::Other, e),
|
||||||
@@ -407,40 +403,35 @@ macro_rules! try_ {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub(crate) fn loop_detected(url: Url) -> Error {
|
||||||
pub fn loop_detected(url: Url) -> Error {
|
|
||||||
Error {
|
Error {
|
||||||
kind: Kind::RedirectLoop,
|
kind: Kind::RedirectLoop,
|
||||||
url: Some(url),
|
url: Some(url),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub(crate) fn too_many_redirects(url: Url) -> Error {
|
||||||
pub fn too_many_redirects(url: Url) -> Error {
|
|
||||||
Error {
|
Error {
|
||||||
kind: Kind::TooManyRedirects,
|
kind: Kind::TooManyRedirects,
|
||||||
url: Some(url),
|
url: Some(url),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub(crate) fn timedout(url: Option<Url>) -> Error {
|
||||||
pub fn timedout(url: Option<Url>) -> Error {
|
|
||||||
Error {
|
Error {
|
||||||
kind: Kind::Io(io_timeout()),
|
kind: Kind::Io(io_timeout()),
|
||||||
url: url,
|
url: url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub(crate) fn client_error(url: Url, status: StatusCode) -> Error {
|
||||||
pub fn client_error(url: Url, status: StatusCode) -> Error {
|
|
||||||
Error {
|
Error {
|
||||||
kind: Kind::ClientError(status),
|
kind: Kind::ClientError(status),
|
||||||
url: Some(url),
|
url: Some(url),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub(crate) fn server_error(url: Url, status: StatusCode) -> Error {
|
||||||
pub fn server_error(url: Url, status: StatusCode) -> Error {
|
|
||||||
Error {
|
Error {
|
||||||
kind: Kind::ServerError(status),
|
kind: Kind::ServerError(status),
|
||||||
url: Some(url),
|
url: Some(url),
|
||||||
|
|||||||
Reference in New Issue
Block a user