reduce Error-related codegen; add PoisonError

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-11-03 12:42:43 +00:00
parent 52f09fdb51
commit 8d251003a2
5 changed files with 16 additions and 1 deletions

View file

@ -10,11 +10,14 @@ impl UnwindSafe for Error {}
impl RefUnwindSafe for Error {}
impl Error {
#[inline]
pub fn panic(self) -> ! { panic_any(self.into_panic()) }
#[must_use]
#[inline]
pub fn from_panic(e: Box<dyn Any + Send>) -> Self { Self::Panic(debug::panic_str(&e), e) }
#[inline]
pub fn into_panic(self) -> Box<dyn Any + Send + 'static> {
match self {
Self::Panic(_, e) | Self::PanicAny(e) => e,
@ -24,6 +27,7 @@ impl Error {
}
/// Get the panic message string.
#[inline]
pub fn panic_str(self) -> Option<&'static str> {
self.is_panic()
.then_some(debug::panic_str(&self.into_panic()))