Improve doc after review

This commit is contained in:
Martin Algesten
2021-12-19 21:10:32 +01:00
parent 8f476e9d29
commit 4aa5480543

View File

@@ -87,6 +87,9 @@ pub enum Error {
}
impl Error {
/// Optionally turn this error into an underlying `Transport`.
///
/// `None` if the underlying error is `Error::Status`.
pub fn into_transport(self) -> Option<Transport> {
match self {
Error::Status(_, _) => None,
@@ -94,6 +97,9 @@ impl Error {
}
}
/// Optionally turn this error into an underlying `Response`.
///
/// `None` if the underlying error is `Error::Transport`.
pub fn into_response(self) -> Option<Response> {
match self {
Error::Status(_, r) => Some(r),
@@ -108,21 +114,6 @@ impl Error {
/// * [`Transport::kind()`] provides a classification (same as for [`Error::kind`]).
/// * [`Transport::message()`] might vary for the same classification to give more context.
/// * [`Transport::source()`](std::error::Error::source) holds the underlying error with even more details.
#[derive(Debug)]
pub struct Transport {
kind: ErrorKind,
message: Option<String>,
url: Option<Url>,
source: Option<Box<dyn error::Error + Send + Sync + 'static>>,
}
impl Transport {
/// The type of error that happened while processing the request.
pub fn kind(&self) -> ErrorKind {
self.kind
}
/// Higher level error details, if there are any.
///
/// ```
/// use ureq::ErrorKind;
@@ -150,6 +141,21 @@ impl Transport {
///
/// assert_eq!(downcast.to_string(), "relative URL without a base");
/// ```
#[derive(Debug)]
pub struct Transport {
kind: ErrorKind,
message: Option<String>,
url: Option<Url>,
source: Option<Box<dyn error::Error + Send + Sync + 'static>>,
}
impl Transport {
/// The type of error that happened while processing the request.
pub fn kind(&self) -> ErrorKind {
self.kind
}
/// Higher level error details, if there are any.
pub fn message(&self) -> Option<&str> {
self.message.as_deref()
}