# Struct std::panic::AssertRecoverSafe [−] [src]

    pub struct AssertRecoverSafe<T>(_);

Unstable (`recover` #27719)

: awaiting feedback

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

#![feature(recover, std_panic)] fn main() { use std::panic::{self, AssertRecoverSafe}; let mut variable = 4; // This code will not compile because the closure captures `&mut variable` // which is not considered panic safe by default. // panic::recover(|| { // variable += 3; // }); // This, however, will compile due to the `AssertRecoverSafe` wrapper let result = { let mut wrapper = AssertRecoverSafe::new(&mut variable); panic::recover(move || { **wrapper += 3; }) }; // ... }

    #![feature(recover, std_panic)]

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

    let mut variable = 4;

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

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

    // This, however, will compile due to the `AssertRecoverSafe` wrapper
    let result = {
        let mut wrapper = AssertRecoverSafe::new(&mut variable);
        panic::recover(move || {
            **wrapper += 3;
        })
    };
    // ...

## Methods

### `impl<T> AssertRecoverSafe<T>`

#### `fn new(t: T) -> AssertRecoverSafe<T>`

Unstable (`recover` #27719)

: awaiting feedback

Creates a new `AssertRecoverSafe` wrapper around the provided type.

## Trait Implementations

### `impl<T> RecoverSafe for AssertRecoverSafe<T>`

### `impl<T> RefRecoverSafe for AssertRecoverSafe<T>`

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

#### `type Target = T`

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

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

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

# 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`)