Skip to content

Commit

Permalink
Merge pull request #683 from epage/error-cleanup
Browse files Browse the repository at this point in the history
fix(error): Move from ErrMode::Convert to ErrrorConvert::convert
  • Loading branch information
epage authored Jan 10, 2025
2 parents 87b491b + 3db4268 commit 4cbcb9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/binary/bits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
Ok(result)
}
Err(ErrMode::Incomplete(n)) => Err(ErrMode::Incomplete(n.map(|u| u.get() / BYTE + 1))),
Err(e) => Err(e.convert()),
Err(e) => Err(ErrorConvert::convert(e)),
}
})
}
Expand Down Expand Up @@ -141,7 +141,7 @@ where
"overflow in turning needed bytes into needed bits",
)),
}),
Err(e) => Err(e.convert()),
Err(e) => Err(ErrorConvert::convert(e)),
}
})
}
Expand Down
16 changes: 13 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@ impl<E> ErrMode<E> {
}
}

/// Automatically converts between errors if the underlying type supports it
/// Deprecated, replaced with [`ErrorConvert`]
#[deprecated(since = "0.6.23", note = "Replaced with `ErrorConvert`")]
pub fn convert<F>(self) -> ErrMode<F>
where
E: ErrorConvert<F>,
{
self.map(ErrorConvert::convert)
ErrorConvert::convert(self)
}

/// Unwrap the mode, returning the underlying error
///
/// Returns `None` for [`ErrMode::Incomplete`]
#[cfg_attr(debug_assertions, track_caller)]
#[inline(always)]
pub fn into_inner(self) -> Option<E> {
match self {
Expand Down Expand Up @@ -214,6 +214,16 @@ impl<I: Stream, E: ParserError<I>> ParserError<I> for ErrMode<E> {
}
}

impl<E1, E2> ErrorConvert<ErrMode<E2>> for ErrMode<E1>
where
E1: ErrorConvert<E2>,
{
#[inline(always)]
fn convert(self) -> ErrMode<E2> {
self.map(|e| e.convert())
}
}

impl<I, EXT, E> FromExternalError<I, EXT> for ErrMode<E>
where
E: FromExternalError<I, EXT>,
Expand Down

0 comments on commit 4cbcb9c

Please sign in to comment.