about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2016-06-16 23:11:17 +0200
committerCorey Farwell <coreyf@rwell.org>2016-06-18 00:17:36 +0200
commit9944b223a29755fe685be292c6a5c31a0ad4b59c (patch)
tree1583edbd84683cf52e3defa4e4763492ee002715 /src/libstd/thread
parent1f9423a87aadacf1dc8f52e3df56f61a7415d4d7 (diff)
downloadrust-9944b223a29755fe685be292c6a5c31a0ad4b59c.tar.gz
rust-9944b223a29755fe685be292c6a5c31a0ad4b59c.zip
Add example in docs for `std::thread::panicking`.
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/mod.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index c8783a60c41..c474aa60b3e 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -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 {