pub struct PanicInfo<'a> { /* private fields */ }Expand description
⌗
core
Passed to #[panic_handler] in no_std, carries a formatted message.
📍code/panic re-exported from core::panic
📜
A struct providing information about a panic.
A PanicInfo structure is passed to the panic handler defined by #[panic_handler].
For the type used by the panic hook mechanism in std, see std::panic::PanicHookInfo.
Implementations§
Source§impl<'a> PanicInfo<'a>
impl<'a> PanicInfo<'a>
1.81.0 · Sourcepub fn message(&self) -> PanicMessage<'_>
pub fn message(&self) -> PanicMessage<'_>
The message that was given to the panic! macro.
§Example
The type returned by this method implements Display, so it can
be passed directly to write!() and similar macros.
#[panic_handler]
fn panic_handler(panic_info: &PanicInfo<'_>) -> ! {
write!(DEBUG_OUTPUT, "panicked: {}", panic_info.message());
loop {}
}1.10.0 · Sourcepub fn location(&self) -> Option<&Location<'_>> ⓘ
pub fn location(&self) -> Option<&Location<'_>> ⓘ
Returns information about the location from which the panic originated, if available.
This method will currently always return Some, but this may change
in future versions.
§Examples
use std::panic;
panic::set_hook(Box::new(|panic_info| {
if let Some(location) = panic_info.location() {
println!("panic occurred in file '{}' at line {}",
location.file(),
location.line(),
);
} else {
println!("panic occurred but can't get location information...");
}
}));
panic!("Normal panic");1.10.0 · Sourcepub fn payload(&self) -> &(dyn Any + Send + 'static)
👎Deprecated since 1.81.0: this never returns anything useful
pub fn payload(&self) -> &(dyn Any + Send + 'static)
this never returns anything useful
Returns the payload associated with the panic.
On this type, core::panic::PanicInfo, this method never returns anything useful.
It only exists because of compatibility with std::panic::PanicHookInfo,
which used to be the same type.
Sourcepub fn can_unwind(&self) -> bool
🔬This is a nightly-only experimental API. (panic_can_unwind)
pub fn can_unwind(&self) -> bool
panic_can_unwind)Returns whether the panic handler is allowed to unwind the stack from the point where the panic occurred.
This is true for most kinds of panics with the exception of panics
caused by trying to unwind out of a Drop implementation or a function
whose ABI does not support unwinding.
It is safe for a panic handler to unwind even when this function returns false, however this will simply cause the panic handler to be called again.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !Send for PanicInfo<'a>
impl<'a> !Sync for PanicInfo<'a>
impl<'a> Freeze for PanicInfo<'a>
impl<'a> RefUnwindSafe for PanicInfo<'a>
impl<'a> Unpin for PanicInfo<'a>
impl<'a> UnsafeUnpin for PanicInfo<'a>
impl<'a> UnwindSafe for PanicInfo<'a>
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice only.