Skip to content

Commit

Permalink
Add example in docs for std::thread::panicking.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jun 17, 2016
1 parent 1f9423a commit 9944b22
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/libstd/thread/mod.rs
Expand Up @@ -321,6 +321,35 @@ pub fn yield_now() {
}

/// Determines whether the current thread is unwinding because of panic.
///
/// # Examples
///
/// ```rust,should_panic
/// use std::thread;
///
/// struct SomeStruct;
///
/// impl Drop for SomeStruct {
/// fn drop(&mut self) {
/// if thread::panicking() {
/// println!("dropped while unwinding");
/// } else {
/// println!("dropped while not unwinding");
/// }
/// }
/// }
///
/// {
/// print!("a: ");
/// let a = SomeStruct;
/// }
///
/// {
/// print!("b: ");
/// let b = SomeStruct;
/// panic!()
/// }
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn panicking() -> bool {
Expand Down

0 comments on commit 9944b22

Please sign in to comment.