# 1.9.0[−][src]Struct std::panic::AssertUnwindSafe

    pub struct AssertUnwindSafe<T>(pub T);

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

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

# Examples

One way to use `AssertUnwindSafe` is to assert that the entire closure itself is unwind 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 unwind 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;
    }));
    // ...Run

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;
        })
    };
    // ...Run

## Trait Implementations

### `impl<T> UnwindSafe for AssertUnwindSafe<T>`[src]

### `impl<T> RefUnwindSafe for AssertUnwindSafe<T>`[src]

### `impl<T: Debug> Debug for AssertUnwindSafe<T>`
1.16.0
[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more

### `impl<T> Deref for AssertUnwindSafe<T>`[src]

#### `type Target = T`

The resulting type after dereferencing.

####
ⓘImportant traits for &'_ mut I

### Important traits for &'_ mut I

`impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`
`fn deref(&self) -> &T`[src]

Dereferences the value.

### `impl<T> DerefMut for AssertUnwindSafe<T>`[src]

####
ⓘImportant traits for &'_ mut I

### Important traits for &'_ mut I

`impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`
`fn deref_mut(&mut self) -> &mut T`[src]

Mutably dereferences the value.

### `impl<R, F: FnOnce() -> R> FnOnce() for AssertUnwindSafe<F>`[src]

#### `type Output = R`

The returned type after the call operator is used.

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

🔬 This is a nightly-only experimental API. (`fn_traits` #29625)

Performs the call operation.

### `impl<'a, F: Future> Future for AssertUnwindSafe<F>`[src]

#### `type Output = F::Output`

🔬 This is a nightly-only experimental API. (`futures_api` #50547)

futures in libcore are unstable

The result of the `Future`.

#### `fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output>`[src]

🔬 This is a nightly-only experimental API. (`futures_api` #50547)

futures in libcore are unstable

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

## Auto Trait Implementations

### `impl<T> Send for AssertUnwindSafe<T> where
T: Send,`

### `impl<T> Sync for AssertUnwindSafe<T> where
T: Sync,`

## Blanket Implementations

### `impl<T> From for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> TryFrom for T where
T: From<U>,` [src]

#### `type Error = !`

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

### `impl<T, U> TryInto for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

### `impl<T, U> Into for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T> Borrow for T where
T: ?Sized,` [src]

####
ⓘImportant traits for &'_ mut I

### Important traits for &'_ mut I

`impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`
`fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut for T where
T: ?Sized,` [src]

####
ⓘImportant traits for &'_ mut I

### Important traits for &'_ mut I

`impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`
`fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn get_type_id(&self) -> TypeId`[src]

🔬 This is a nightly-only experimental API. (`get_type_id` #27745)

this method will likely be replaced by an associated static

Gets the `TypeId` of `self`. Read more

### `impl<A, F> FnBox for F where
F: FnOnce<A>,` [src]

#### `type Output = <F as FnOnce<A>>::Output`

🔬 This is a nightly-only experimental API. (`fnbox` #28796)

will be deprecated if and when `Box<FnOnce>` becomes usable

#### `fn call_box(self: Box<F>, args: A) -> <F as FnOnce<A>>::Output`[src]

🔬 This is a nightly-only experimental API. (`fnbox` #28796)

will be deprecated if and when `Box<FnOnce>` becomes usable

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

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

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)