A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://doc.rust-lang.org/nightly/std/panic/struct.AssertUnwindSafe.html below:

AssertUnwindSafe in std::panic - Rust

Struct AssertUnwindSafe1.9.0 · Source
pub struct AssertUnwindSafe<T>(pub T);
Expand description

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 might 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;

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;
    })
};
Source§ Source§ 🔬This is a nightly-only experimental API. (async_iterator #79024)

The type of items yielded by the async iterator.

Source§ 🔬This is a nightly-only experimental API. (async_iterator #79024)

Attempts to pull out the next value of this async iterator, registering the current task for wakeup if the value is not yet available, and returning

None

if the async iterator is exhausted.

Read more Source§ 🔬This is a nightly-only experimental API. (async_iterator #79024)

Returns the bounds on the remaining length of the async iterator.

Read more 1.16.0 · Source§ 1.62.0 · Source§ 1.9.0 · Source§ Source§

The resulting type after dereferencing.

Source§

Dereferences the value.

1.9.0 · Source§ Source§

Mutably dereferences the value.

1.9.0 · Source§ Source§

The returned type after the call operator is used.

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

Performs the call operation.

1.36.0 · Source§ Source§

The type of value produced on completion.

Source§

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

Read more 1.9.0 · Source§ 1.9.0 · Source§

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4