Struct v9::prelude_lib::panic::AssertUnwindSafe 1.9.0[−][src]
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; })); // ...
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> Debug for AssertUnwindSafe<T> where
T: Debug,
1.16.0[src]
T: Debug,
impl<T> Deref for AssertUnwindSafe<T>
[src]
impl<T> DerefMut for AssertUnwindSafe<T>
[src]
impl<R, F> FnOnce() for AssertUnwindSafe<F> where
F: FnOnce() -> R,
[src]
F: FnOnce() -> R,
type Output = R
The returned type after the call operator is used.
pub extern "rust-call" fn call_once(self, _args: ()) -> R
[src]
impl<F> Future for AssertUnwindSafe<F> where
F: Future,
1.36.0[src]
F: Future,
type Output = <F as Future>::Output
The type of value produced on completion.
pub fn poll(
self: Pin<&mut AssertUnwindSafe<F>>,
cx: &mut Context<'_>
) -> Poll<<AssertUnwindSafe<F> as Future>::Output>
[src]
self: Pin<&mut AssertUnwindSafe<F>>,
cx: &mut Context<'_>
) -> Poll<<AssertUnwindSafe<F> as Future>::Output>
impl<T> RefUnwindSafe for AssertUnwindSafe<T>
[src]
impl<S> Stream for AssertUnwindSafe<S> where
S: Stream,
[src]
S: Stream,
type Item = <S as Stream>::Item
async_stream
)The type of items yielded by the stream.
pub fn poll_next(
self: Pin<&mut AssertUnwindSafe<S>>,
cx: &mut Context<'_>
) -> Poll<Option<<S as Stream>::Item>>
[src]
self: Pin<&mut AssertUnwindSafe<S>>,
cx: &mut Context<'_>
) -> Poll<Option<<S as Stream>::Item>>
pub fn size_hint(&self) -> (usize, Option<usize>)
[src]
impl<T> UnwindSafe for AssertUnwindSafe<T>
[src]
Auto Trait Implementations
impl<T> Send for AssertUnwindSafe<T> where
T: Send,
T: Send,
impl<T> Sync for AssertUnwindSafe<T> where
T: Sync,
T: Sync,
impl<T> Unpin for AssertUnwindSafe<T> where
T: Unpin,
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<X> ForeignKey for X
[src]
fn __v9_link_foreign_table_name() -> Option<Name>
[src]
fn __v9_link_foreign_key<LM: TableMarker>(_universe: &mut Universe)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<F> IntoFuture for F where
F: Future,
[src]
F: Future,
type Output = <F as Future>::Output
into_future
)The output that the future will produce on completion.
type Future = F
into_future
)Which kind of future are we turning this into?
pub fn into_future(self) -> <F as IntoFuture>::Future
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,