Struct bitflags::__core::panic::AssertRecoverSafe [] [src]

pub struct AssertRecoverSafe<T>(_);
Unstable (recover)

: 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)]

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)

: awaiting feedback

Creates a new AssertRecoverSafe wrapper around the provided type.

fn into_inner(self) -> T

Unstable (recover)

: awaiting feedback

Consumes the AssertRecoverSafe, returning the wrapped value.

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