# Struct bitflags::__core::panic::AssertUnwindSafe [−] [src]

    pub struct AssertUnwindSafe<T>(pub T);

1.9.0

A simple wrapper around a type to assert that it is panic safe.

When using `recover` it may be the case that some of the closed over variables are not panic safe. For example if `&mut T` is captured the compiler will generate a warning indicating that it is not panic safe. It may not be the case, however, that this is actually a problem due to the specific usage of `recover` if panic safety is specifically taken into account. This wrapper struct is useful for a quick and lightweight annotation that a variable is indeed panic safe.

# Examples

One way to use `AssertUnwindSafe` is to assert that the entire closure itself is recover safe, bypassing all checks for all variables:

    use std::panic::{self, AssertUnwindSafe};

    let mut variable = 4;

    // This code will not compile because the closure captures `&mut variable`
    // which is not considered panic safe by default.

    // panic::catch_unwind(|| {
    //     variable += 3;
    // });

    // This, however, will compile due to the `AssertUnwindSafe` wrapper
    let result = panic::catch_unwind(AssertUnwindSafe(|| {
        variable += 3;
    }));
    // ...

Wrapping the entire closure amounts to a blanket assertion that all captured variables are unwind safe. This has the downside that if new captures are added in the future, they will also be considered unwind safe. Therefore, you may prefer to just wrap individual captures, as shown below. This is more annotation, but it ensures that if a new capture is added which is not unwind safe, you will get a compilation error at that time, which will allow you to consider whether that new capture in fact represent a bug or not.

    use std::panic::{self, AssertUnwindSafe};

    let mut variable = 4;
    let other_capture = 3;

    let result = {
        let mut wrapper = AssertUnwindSafe(&mut variable);
        panic::catch_unwind(move || {
            **wrapper += other_capture;
        })
    };
    // ...

## Trait Implementations

### `impl<T> UnwindSafe for AssertUnwindSafe<T>`

### `impl<T> RefUnwindSafe for AssertUnwindSafe<T>`

### `impl<T> Deref for AssertUnwindSafe<T>`

#### `type Target = T`

#### `fn deref(&self) -> &T`

### `impl<T> DerefMut for AssertUnwindSafe<T>`

#### `fn deref_mut(&mut self) -> &mut T`

### `impl<R, F> FnOnce() for AssertUnwindSafe<F> where F: FnOnce() -> R`

#### `type Output = R`

#### `extern "rust-call" fn call_once(self, _args: ()) -> R`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)