pub fn preserve_panic_message<F: FnOnce(&mut EasyCurses) -> R + UnwindSafe, R>(user_function: F) -> Result<R, Option<String>> {
  let result = catch_unwind(|| {
    // Normally calling `expect` is asking for eventual trouble to bite us,
    // but we're specifically inside a `catch_unwind` block so it's fine.
    let mut easy = EasyCurses::initialize_system().expect("Curses double-initialization.");
    user_function(&mut easy)
  });
  result.map_err(|e| match e.downcast_ref::<&str>() {
    Some(andstr) => Some(andstr.to_string()),
    None => match e.downcast_ref::<String>() {
      Some(string) => Some(string.to_string()),
      None => None,
    },
  })
}
/// Wraps the use of curses with `catch_unwind` to preserve panic info.
///
/// Normally, if your program panics while in curses mode the panic message
/// prints immediately and then is destroyed before you can see it by the
/// automatic cleanup of curses mode. Instead, this runs the function you pass
/// it within `catch_unwind` and when there's a panic it catches the panic value
/// and attempts to downcast it into a `String` you can print out or log or
/// whatever you like. Since a panic value can be anything at all this won't
/// always succeed, thus the `Option` wrapper on the `Err` case. Regardless of
/// what of `Result` you get back, curses mode will be fully cleaned up and shut
/// down by the time this function returns.
///
/// Note that you *don't* have to use this if you just want your terminal
/// restored to normal when your program panics while in curses mode. That is
/// handled automatically by the `Drop` implementation of `EasyCurses`. You only
/// need to use this if you care about the panic message itself.
Wraps the use of curses with `catch_unwind` to preserve panic info.
Normally, if your program panics while in curses mode the panic message
prints immediately and then is destroyed before you can see it by the
automatic cleanup of curses mode. Instead, this runs the function you pass
it within `catch_unwind` and when there's a panic it catches the panic value
and attempts to downcast it into a `String` you can print out or log or
whatever you like. Since a panic value can be anything at all this won't
always succeed, thus the `Option` wrapper on the `Err` case. Regardless of
what of `Result` you get back, curses mode will be fully cleaned up and shut
down by the time this function returns.

Note that you *don't* have to use this if you just want your terminal
restored to normal when your program panics while in curses mode. That is
handled automatically by the `Drop` implementation of `EasyCurses`. You only
need to use this if you care about the panic message itself.
Wraps the use of curses with ` catch_unwind ` to preserve panic info . Normally if your program panics while in curses mode the panic message prints immediately and then is destroyed before you can see it by the automatic cleanup of curses mode . Instead this runs the function you pass it within ` catch_unwind ` and when there ' s a panic it catches the panic value and attempts to downcast it into a ` String ` you can print out or log or whatever you like . Since a panic value can be anything at all this won ' t always succeed thus the ` Option ` wrapper on the ` Err ` case . Regardless of what of ` Result ` you get back curses mode will be fully cleaned up and shut down by the time this function returns . Note that you * don ' t * have to use this if you just want your terminal restored to normal when your program panics while in curses mode . That is handled automatically by the ` Drop ` implementation of ` EasyCurses ` . You only need to use this if you care about the panic message itself .
pub fn preserve_panic_message<F: FnOnce(&mut EasyCurses) -> R + UnwindSafe, R>(user_function: F) -> Result<R, Option<String>> {
  let result = catch_unwind(|| {
    // Normally calling `expect` is asking for eventual trouble to bite us,
    // but we're specifically inside a `catch_unwind` block so it's fine.
    let mut easy = EasyCurses::initialize_system().expect("Curses double-initialization.");
    user_function(&mut easy)
  });
  result.map_err(|e| match e.downcast_ref::<&str>() {
    Some(andstr) => Some(andstr.to_string()),
    None => match e.downcast_ref::<String>() {
      Some(string) => Some(string.to_string()),
      None => None,
    },
  })
}
pub fn preserve_panic_message < F : FnOnce ( & mut EasyCurses ) -> R + UnwindSafe , R > ( user_function : F ) -> Result < R , Option < String > > { let result = catch_unwind ( | | { // Normally calling `expect` is asking for eventual trouble to bite us, // but we're specifically inside a `catch_unwind` block so it's fine. let mut easy = EasyCurses :: initialize_system ( ) . expect ( " " ) ; user_function ( & mut easy ) } ) ; result . map_err ( | e | match e . downcast_ref :: < & str > ( ) { Some ( andstr ) => Some ( andstr . to_string ( ) ) , None => match e . downcast_ref :: < String > ( ) { Some ( string ) => Some ( string . to_string ( ) ) , None => None , } , } ) }
Wraps the use of curses with `catch_unwind` to preserve panic info.
Wraps the use of curses with ` catch_unwind ` to preserve panic info .
user_function
F
user_function
F