]> git.lizzy.rs Git - rust.git/commitdiff
Add example in docs for `std::thread::panicking`.
authorCorey Farwell <coreyf@rwell.org>
Thu, 16 Jun 2016 21:11:17 +0000 (23:11 +0200)
committerCorey Farwell <coreyf@rwell.org>
Fri, 17 Jun 2016 22:17:36 +0000 (00:17 +0200)
src/libstd/thread/mod.rs

index c8783a60c4117d23ee12211de55de900f111ec1e..c474aa60b3ee4e2b098c13cae7f0290a091d7361 100644 (file)
@@ -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 {