Skip to content

Commit

Permalink
Add a few more lines of documentation to Error functionality
Browse files Browse the repository at this point in the history
Add a few more lines of documentation to the Error functionality.

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o committed Sep 11, 2023
1 parent 0dbf152 commit a0dfb49
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,21 @@ impl From<io::Error> for Error {
}
}


/// A trait providing ergonomic chaining capabilities to [`Error`].
pub trait ErrorExt: private::Sealed {
/// The output type produced by [`context`](Self::context) and
/// [`with_context`](Self::with_context).
type Output;

/// Add context to this error.
// If we had specialization of sorts we could be more lenient as to
// what we can accept, but for now this method always works with
// static strings and nothing else.
fn context<C>(self, context: C) -> Self::Output
where
C: IntoCowStr;

/// Add context to this error, using a closure for lazy evaluation.
fn with_context<C, F>(self, f: F) -> Self::Output
where
C: IntoCowStr,
Expand All @@ -458,14 +462,14 @@ pub trait ErrorExt: private::Sealed {
impl ErrorExt for Error {
type Output = Error;

fn context<C>(self, context: C) -> Error
fn context<C>(self, context: C) -> Self::Output
where
C: IntoCowStr,
{
self.layer_context(context.into_cow_str())
}

fn with_context<C, F>(self, f: F) -> Error
fn with_context<C, F>(self, f: F) -> Self::Output
where
C: IntoCowStr,
F: FnOnce() -> C,
Expand Down Expand Up @@ -505,14 +509,14 @@ where
impl ErrorExt for io::Error {
type Output = Error;

fn context<C>(self, context: C) -> Error
fn context<C>(self, context: C) -> Self::Output
where
C: IntoCowStr,
{
Error::from(self).context(context)
}

fn with_context<C, F>(self, f: F) -> Error
fn with_context<C, F>(self, f: F) -> Self::Output
where
C: IntoCowStr,
F: FnOnce() -> C,
Expand All @@ -525,14 +529,14 @@ impl ErrorExt for io::Error {
impl ErrorExt for gimli::Error {
type Output = Error;

fn context<C>(self, context: C) -> Error
fn context<C>(self, context: C) -> Self::Output
where
C: IntoCowStr,
{
Error::from(self).context(context)
}

fn with_context<C, F>(self, f: F) -> Error
fn with_context<C, F>(self, f: F) -> Self::Output
where
C: IntoCowStr,
F: FnOnce() -> C,
Expand Down

0 comments on commit a0dfb49

Please sign in to comment.