Skip to content

Commit d06f1dc

Browse files
authored
Auto merge of #34313 - frewsxcv:panicking-example, r=steveklabnik
Add example in docs for `std::thread::panicking`. None
2 parents 3313e50 + 9944b22 commit d06f1dc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/libstd/thread/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,35 @@ pub fn yield_now() {
321321
}
322322

323323
/// Determines whether the current thread is unwinding because of panic.
324+
///
325+
/// # Examples
326+
///
327+
/// ```rust,should_panic
328+
/// use std::thread;
329+
///
330+
/// struct SomeStruct;
331+
///
332+
/// impl Drop for SomeStruct {
333+
/// fn drop(&mut self) {
334+
/// if thread::panicking() {
335+
/// println!("dropped while unwinding");
336+
/// } else {
337+
/// println!("dropped while not unwinding");
338+
/// }
339+
/// }
340+
/// }
341+
///
342+
/// {
343+
/// print!("a: ");
344+
/// let a = SomeStruct;
345+
/// }
346+
///
347+
/// {
348+
/// print!("b: ");
349+
/// let b = SomeStruct;
350+
/// panic!()
351+
/// }
352+
/// ```
324353
#[inline]
325354
#[stable(feature = "rust1", since = "1.0.0")]
326355
pub fn panicking() -> bool {

0 commit comments

Comments
 (0)