[−][src]Function cool_asserts::get_panic_message
pub fn get_panic_message(panic: &Box<dyn Any + Send>) -> Option<&str>
Get the panic message as a &str
, if available
While a panic value can be any type, usually it is either a String
or a str
, hidden inside a Box<dyn Any + Send + Sync>
(see
std::thread::Result
for more info). This function gets the panic
message as an &str (if available) from a panic value.
use std::panic::catch_unwind; use cool_asserts::get_panic_message; let result = catch_unwind(|| panic!("{}, {}!", "Hello", "World")); let panic = result.unwrap_err(); let message = get_panic_message(&panic).unwrap(); assert_eq!(message, "Hello, World!");