alloc/panicking.rs
1#![doc(hidden)]
2#![unstable(feature = "std_internals", issue = "none")]
3
4use core::any::Any;
5use core::fmt::Display;
6
7use crate::boxed::Box;
8
9/// An internal trait used by std to pass data from std to `panic_unwind` and
10/// other panic runtimes. Not intended to be stabilized any time soon, do not
11/// use.
12pub trait PanicPayload: Display {
13 /// Take full ownership of the contents.
14 ///
15 /// After this method got called, only some dummy default value is left in `self`.
16 /// Calling this method twice, or calling `get` after calling this method, is an error.
17 ///
18 /// The argument is borrowed because the panic runtime (`__rust_start_panic`) only
19 /// gets a borrowed `dyn PanicPayload`.
20 fn take_box(&mut self) -> Box<dyn Any + Send>;
21
22 /// Just borrow the contents.
23 fn get(&mut self) -> &(dyn Any + Send);
24
25 /// Tries to borrow the contents as `&str`, if possible without doing any allocations.
26 fn as_str(&mut self) -> Option<&str> {
27 None
28 }
29}