Trait v9::prelude_lib::panic::UnwindSafe 1.9.0[−][src]
A marker trait which represents “panic safe” types in Rust.
This trait is implemented by default for many types and behaves similarly in
terms of inference of implementation to the Send
and Sync
traits. The
purpose of this trait is to encode what types are safe to cross a catch_unwind
boundary with no fear of unwind safety.
What is unwind safety?
In Rust a function can “return” early if it either panics or calls a function which transitively panics. This sort of control flow is not always anticipated, and has the possibility of causing subtle bugs through a combination of two critical components:
- A data structure is in a temporarily invalid state when the thread panics.
- This broken invariant is then later observed.
Typically in Rust, it is difficult to perform step (2) because catching a
panic involves either spawning a thread (which in turns makes it difficult
to later witness broken invariants) or using the catch_unwind
function in this
module. Additionally, even if an invariant is witnessed, it typically isn’t a
problem in Rust because there are no uninitialized values (like in C or C++).
It is possible, however, for logical invariants to be broken in Rust,
which can end up causing behavioral bugs. Another key aspect of unwind safety
in Rust is that, in the absence of unsafe
code, a panic cannot lead to
memory unsafety.
That was a bit of a whirlwind tour of unwind safety, but for more information about unwind safety and how it applies to Rust, see an associated RFC.
What is UnwindSafe
?
Now that we’ve got an idea of what unwind safety is in Rust, it’s also
important to understand what this trait represents. As mentioned above, one
way to witness broken invariants is through the catch_unwind
function in this
module as it allows catching a panic and then re-using the environment of
the closure.
Simply put, a type T
implements UnwindSafe
if it cannot easily allow
witnessing a broken invariant through the use of catch_unwind
(catching a
panic). This trait is an auto trait, so it is automatically implemented for
many types, and it is also structurally composed (e.g., a struct is unwind
safe if all of its components are unwind safe).
Note, however, that this is not an unsafe trait, so there is not a succinct
contract that this trait is providing. Instead it is intended as more of a
“speed bump” to alert users of catch_unwind
that broken invariants may be
witnessed and may need to be accounted for.
Who implements UnwindSafe
?
Types such as &mut T
and &RefCell<T>
are examples which are not
unwind safe. The general idea is that any mutable state which can be shared
across catch_unwind
is not unwind safe by default. This is because it is very
easy to witness a broken invariant outside of catch_unwind
as the data is
simply accessed as usual.
Types like &Mutex<T>
, however, are unwind safe because they implement
poisoning by default. They still allow witnessing a broken invariant, but
they already provide their own “speed bumps” to do so.
When should UnwindSafe
be used?
It is not intended that most types or functions need to worry about this trait.
It is only used as a bound on the catch_unwind
function and as mentioned
above, the lack of unsafe
means it is mostly an advisory. The
AssertUnwindSafe
wrapper struct can be used to force this trait to be
implemented for any closed over variables passed to catch_unwind
.
Implementations on Foreign Types
impl UnwindSafe for Argument
impl UnwindSafe for FormatSpec
impl UnwindSafe for Alignment
impl UnwindSafe for Count
impl<K, V, S> UnwindSafe for HashMap<K, V, S> where
K: UnwindSafe,
V: UnwindSafe,
S: UnwindSafe,
[src]
K: UnwindSafe,
V: UnwindSafe,
S: UnwindSafe,
impl<T> UnwindSafe for Arc<T> where
T: RefUnwindSafe + ?Sized,
[src]
T: RefUnwindSafe + ?Sized,
impl<T, F> UnwindSafe for SyncLazy<T, F> where
F: UnwindSafe,
SyncOnceCell<T>: UnwindSafe,
[src]
F: UnwindSafe,
SyncOnceCell<T>: UnwindSafe,
impl<T> UnwindSafe for Mutex<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T> UnwindSafe for RwLock<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T> UnwindSafe for *mut T where
T: RefUnwindSafe + ?Sized,
[src]
T: RefUnwindSafe + ?Sized,
impl<'_, T> !UnwindSafe for &'_ mut T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> UnwindSafe for NonNull<T> where
T: RefUnwindSafe + ?Sized,
[src]
T: RefUnwindSafe + ?Sized,
impl<T> UnwindSafe for Rc<T> where
T: RefUnwindSafe + ?Sized,
[src]
T: RefUnwindSafe + ?Sized,
impl<T> UnwindSafe for SyncOnceCell<T> where
T: UnwindSafe,
[src]
T: UnwindSafe,
impl<T> UnwindSafe for *const T where
T: RefUnwindSafe + ?Sized,
[src]
T: RefUnwindSafe + ?Sized,
impl<'_, T> UnwindSafe for &'_ T where
T: RefUnwindSafe + ?Sized,
[src]
T: RefUnwindSafe + ?Sized,
impl UnwindSafe for isize
impl<T> UnwindSafe for [T] where
T: UnwindSafe,
T: UnwindSafe,
impl UnwindSafe for [u8]
impl UnwindSafe for char
impl UnwindSafe for u128
impl UnwindSafe for u16
impl UnwindSafe for i128
impl UnwindSafe for i16
impl UnwindSafe for str
impl UnwindSafe for f64
impl UnwindSafe for u64
impl UnwindSafe for u8
impl UnwindSafe for i64
impl UnwindSafe for i8
impl<T, const N: usize> UnwindSafe for [T; N] where
T: UnwindSafe,
T: UnwindSafe,
impl UnwindSafe for bool
impl UnwindSafe for f32
impl UnwindSafe for u32
impl UnwindSafe for usize
impl UnwindSafe for i32
Loading content...Implementors
impl<T> UnwindSafe for AssertUnwindSafe<T>
[src]
Auto implementors
impl !UnwindSafe for Rez
impl !UnwindSafe for Kernel
impl !UnwindSafe for Selection
impl !UnwindSafe for GuardMut
impl !UnwindSafe for GuardRef
impl !UnwindSafe for Locked
impl UnwindSafe for Access
impl UnwindSafe for LockState
impl UnwindSafe for Ordering
impl UnwindSafe for v9::prelude_lib::fmt::Alignment
impl UnwindSafe for Universe
impl UnwindSafe for Error
impl UnwindSafe for TypeId
impl UnwindSafe for PropertyHeader
impl UnwindSafe for Marker
impl UnwindSafe for Row
impl UnwindSafe for ColumnHeader
impl UnwindSafe for TableHeader
impl<'a> !UnwindSafe for PushArgs<'a>
impl<'a> !UnwindSafe for Arguments<'a>
impl<'a> !UnwindSafe for Formatter<'a>
impl<'a> !UnwindSafe for PanicInfo<'a>
impl<'a> !UnwindSafe for __Edit<'a>
impl<'a> !UnwindSafe for __Read<'a>
impl<'a> !UnwindSafe for __Write<'a>
impl<'a> UnwindSafe for UniverseRef<'a>
impl<'a> UnwindSafe for Location<'a>
impl<'a> UnwindSafe for RowRef<'a>
impl<'a, 'b> !UnwindSafe for DebugList<'a, 'b>
impl<'a, 'b> !UnwindSafe for DebugMap<'a, 'b>
impl<'a, 'b> !UnwindSafe for DebugSet<'a, 'b>
impl<'a, 'b> !UnwindSafe for DebugStruct<'a, 'b>
impl<'a, 'b> !UnwindSafe for DebugTuple<'a, 'b>
impl<'a, I> UnwindSafe for IdRange<'a, I> where
I: UnwindSafe,
I: UnwindSafe,
impl<'a, I> UnwindSafe for IdRangeIter<'a, I> where
I: UnwindSafe,
I: UnwindSafe,
impl<'a, M> !UnwindSafe for ListRemoving<'a, M>
impl<'a, M> !UnwindSafe for RmId<'a, M>
impl<'a, M> UnwindSafe for CheckedId<'a, M> where
M: RefUnwindSafe,
<M as TableMarker>::RawId: UnwindSafe,
M: RefUnwindSafe,
<M as TableMarker>::RawId: UnwindSafe,
impl<'a, M> UnwindSafe for CheckedIter<'a, M> where
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
impl<'a, M> UnwindSafe for RunListIter<'a, M> where
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
impl<'a, M, T> !UnwindSafe for EditColumn<'a, M, T>
impl<'a, M, T> !UnwindSafe for FastEditColumn<'a, M, T>
impl<'a, M, T> !UnwindSafe for WriteColumn<'a, M, T>
impl<'a, M, T> UnwindSafe for ReadColumn<'a, M, T> where
M: RefUnwindSafe,
T: RefUnwindSafe,
M: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T> !UnwindSafe for MutButRef<'a, T>
impl<E> !UnwindSafe for Tracker<E>
impl<FM> !UnwindSafe for Select<FM>
impl<Idx> UnwindSafe for Range<Idx> where
Idx: UnwindSafe,
Idx: UnwindSafe,
impl<M> UnwindSafe for Deleted<M> where
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
impl<M> UnwindSafe for Moved<M> where
<M as TableMarker>::RawId: UnwindSafe,
<M as TableMarker>::RawId: UnwindSafe,
impl<M> UnwindSafe for Pushed<M> where
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
impl<M> UnwindSafe for Id<M> where
<M as TableMarker>::RawId: UnwindSafe,
<M as TableMarker>::RawId: UnwindSafe,
impl<M> UnwindSafe for IdList<M> where
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
impl<M> UnwindSafe for RunList<M> where
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
<M as TableMarker>::RawId: RefUnwindSafe + UnwindSafe,
impl<M, T> UnwindSafe for Column<M, T> where
M: UnwindSafe,
T: UnwindSafe,
M: UnwindSafe,
T: UnwindSafe,
impl<M, T> UnwindSafe for Edited<M, T> where
M: RefUnwindSafe,
T: RefUnwindSafe + UnwindSafe,
<M as TableMarker>::RawId: UnwindSafe,
M: RefUnwindSafe,
T: RefUnwindSafe + UnwindSafe,
<M as TableMarker>::RawId: UnwindSafe,
impl<M, T> UnwindSafe for ColumnIndex<M, T> where
T: RefUnwindSafe,
<M as TableMarker>::RawId: RefUnwindSafe,
T: RefUnwindSafe,
<M as TableMarker>::RawId: RefUnwindSafe,
impl<T> UnwindSafe for KernelArg<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> UnwindSafe for Discriminant<T> where
<T as DiscriminantKind>::Discriminant: UnwindSafe,
<T as DiscriminantKind>::Discriminant: UnwindSafe,
impl<T> UnwindSafe for SyncRef<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> UnwindSafe for MaybeUninit<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T: ?Sized> UnwindSafe for ManuallyDrop<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T: ?Sized> UnwindSafe for PhantomData<T> where
T: UnwindSafe,
T: UnwindSafe,