Add basic doc examples for std::panic::{set_hook, take_hook}
.
This commit is contained in:
parent
141012dd52
commit
5505ebc31d
@ -84,6 +84,20 @@ static mut HOOK: Hook = Hook::Default;
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if called from a panicking thread.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// The following will print "Custom panic hook":
|
||||
///
|
||||
/// ```should_panic
|
||||
/// use std::panic;
|
||||
///
|
||||
/// panic::set_hook(Box::new(|_| {
|
||||
/// println!("Custom panic hook");
|
||||
/// }));
|
||||
///
|
||||
/// panic!("Normal panic");
|
||||
/// ```
|
||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||
pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {
|
||||
if thread::panicking() {
|
||||
@ -109,6 +123,22 @@ pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if called from a panicking thread.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// The following will print "Normal panic":
|
||||
///
|
||||
/// ```should_panic
|
||||
/// use std::panic;
|
||||
///
|
||||
/// panic::set_hook(Box::new(|_| {
|
||||
/// println!("Custom panic hook");
|
||||
/// }));
|
||||
///
|
||||
/// let _ = panic::take_hook();
|
||||
///
|
||||
/// panic!("Normal panic");
|
||||
/// ```
|
||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||
pub fn take_hook() -> Box<Fn(&PanicInfo) + 'static + Sync + Send> {
|
||||
if thread::panicking() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user