kvarn_async::prelude::compact_str::core::panic

Trait UnwindSafe

1.41.0 · source
pub auto trait UnwindSafe { }
Expand description

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:

  1. A data structure is in a temporarily invalid state when the thread panics.
  2. 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 turn 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.

Implementors§

1.9.0 · source§

impl UnwindSafe for Stderr

1.9.0 · source§

impl UnwindSafe for StderrLock<'_>

1.9.0 · source§

impl UnwindSafe for Stdout

1.9.0 · source§

impl UnwindSafe for StdoutLock<'_>

1.9.0 · source§

impl UnwindSafe for Condvar

1.59.0 · source§

impl UnwindSafe for std::sync::once::Once

§

impl UnwindSafe for AbortHandle

§

impl UnwindSafe for Notify

§

impl UnwindSafe for Runtime

1.64.0 · source§

impl<K, V, A> UnwindSafe for BTreeMap<K, V, A>

1.36.0 · source§

impl<K, V, S> UnwindSafe for HashMap<K, V, S>
where K: UnwindSafe, V: UnwindSafe, S: UnwindSafe,

1.9.0 · source§

impl<T> !UnwindSafe for &mut T
where T: ?Sized,

1.9.0 · source§

impl<T> UnwindSafe for *const T
where T: RefUnwindSafe + ?Sized,

1.9.0 · source§

impl<T> UnwindSafe for *mut T
where T: RefUnwindSafe + ?Sized,

1.9.0 · source§

impl<T> UnwindSafe for &T
where T: RefUnwindSafe + ?Sized,

1.28.0 · source§

impl<T> UnwindSafe for NonZero<T>

1.25.0 · source§

impl<T> UnwindSafe for NonNull<T>
where T: RefUnwindSafe + ?Sized,

source§

impl<T> UnwindSafe for Receiver<T>

source§

impl<T> UnwindSafe for Sender<T>

1.9.0 · source§

impl<T> UnwindSafe for std::sync::mutex::Mutex<T>
where T: ?Sized,

1.70.0 · source§

impl<T> UnwindSafe for OnceLock<T>
where T: UnwindSafe,

source§

impl<T> UnwindSafe for ReentrantLock<T>
where T: UnwindSafe + ?Sized,

1.9.0 · source§

impl<T> UnwindSafe for std::sync::rwlock::RwLock<T>
where T: ?Sized,

1.9.0 · source§

impl<T> UnwindSafe for AssertUnwindSafe<T>

§

impl<T> UnwindSafe for JoinHandle<T>

1.9.0 · source§

impl<T, A> UnwindSafe for Arc<T, A>

1.9.0 · source§

impl<T, A> UnwindSafe for Rc<T, A>

1.80.0 · source§

impl<T, F> UnwindSafe for LazyLock<T, F>
where T: UnwindSafe, F: UnwindSafe,

Auto implementors§

§

impl !UnwindSafe for kvarn_async::prelude::io::Error

§

impl UnwindSafe for IpAddr

§

impl UnwindSafe for SocketAddr

§

impl UnwindSafe for kvarn_async::prelude::fmt::Alignment

§

impl UnwindSafe for ErrorKind

§

impl UnwindSafe for SeekFrom

§

impl UnwindSafe for Ipv6MulticastScope

§

impl UnwindSafe for Shutdown

§

impl UnwindSafe for CacheControlError

§

impl UnwindSafe for kvarn_async::prelude::parse::Error

§

impl UnwindSafe for RequestParseStage

§

impl UnwindSafe for SanitizeError

§

impl UnwindSafe for ToCompactStringError

§

impl UnwindSafe for AsciiChar

§

impl UnwindSafe for kvarn_async::prelude::compact_str::core::cmp::Ordering

§

impl UnwindSafe for Infallible

§

impl UnwindSafe for c_void

§

impl UnwindSafe for BasicBlock

§

impl UnwindSafe for UnwindTerminateReason

§

impl UnwindSafe for FpCategory

§

impl UnwindSafe for IntErrorKind

§

impl UnwindSafe for SearchStep

§

impl UnwindSafe for kvarn_async::prelude::compact_str::core::sync::atomic::Ordering

§

impl UnwindSafe for UninitSlice

§

impl UnwindSafe for PresentArguments

§

impl UnwindSafe for PresentExtensions

§

impl UnwindSafe for PresentExtensionsIter

§

impl UnwindSafe for kvarn_async::prelude::fmt::Error

§

impl UnwindSafe for InvalidHeaderName

§

impl UnwindSafe for InvalidHeaderValue

§

impl UnwindSafe for MaxSizeReached

§

impl UnwindSafe for ToStrError

§

impl UnwindSafe for kvarn_async::prelude::io::Empty

§

impl UnwindSafe for kvarn_async::prelude::io::Repeat

§

impl UnwindSafe for Sink

§

impl UnwindSafe for Stdin

§

impl UnwindSafe for WriterPanicked

§

impl UnwindSafe for AddrParseError

§

impl UnwindSafe for IntoIncoming

§

impl UnwindSafe for Ipv4Addr

§

impl UnwindSafe for Ipv6Addr

§

impl UnwindSafe for SocketAddrV4

§

impl UnwindSafe for SocketAddrV6

§

impl UnwindSafe for TcpListener

§

impl UnwindSafe for TcpStream

§

impl UnwindSafe for UdpSocket

§

impl UnwindSafe for CacheControl

§

impl UnwindSafe for CriticalRequestComponents

§

impl UnwindSafe for ParseBoolError

§

impl UnwindSafe for Utf8Error

§

impl UnwindSafe for kvarn_async::prelude::Bytes

§

impl UnwindSafe for BytesMut

§

impl UnwindSafe for CompactString

§

impl UnwindSafe for Duration

§

impl UnwindSafe for HeaderName

§

impl UnwindSafe for HeaderValue

§

impl UnwindSafe for Instant

§

impl UnwindSafe for Method

§

impl UnwindSafe for Path

§

impl UnwindSafe for PathBuf

§

impl UnwindSafe for StatusCode

§

impl UnwindSafe for Uri

§

impl UnwindSafe for Version

§

impl UnwindSafe for WriteableBytes

§

impl UnwindSafe for Authority

§

impl UnwindSafe for Builder

§

impl UnwindSafe for InvalidUri

§

impl UnwindSafe for InvalidUriParts

§

impl UnwindSafe for Parts

§

impl UnwindSafe for PathAndQuery

§

impl UnwindSafe for Scheme

§

impl UnwindSafe for ReserveError

§

impl UnwindSafe for Utf16Error

§

impl UnwindSafe for AllocError

§

impl UnwindSafe for Layout

§

impl UnwindSafe for LayoutError

§

impl UnwindSafe for TypeId

§

impl UnwindSafe for CpuidResult

§

impl UnwindSafe for __m128

§

impl UnwindSafe for __m128bh

§

impl UnwindSafe for __m128d

§

impl UnwindSafe for __m128h

§

impl UnwindSafe for __m128i

§

impl UnwindSafe for __m256

§

impl UnwindSafe for __m256bh

§

impl UnwindSafe for __m256d

§

impl UnwindSafe for __m256h

§

impl UnwindSafe for __m256i

§

impl UnwindSafe for __m512

§

impl UnwindSafe for __m512bh

§

impl UnwindSafe for __m512d

§

impl UnwindSafe for __m512h

§

impl UnwindSafe for __m512i

§

impl UnwindSafe for bf16

§

impl UnwindSafe for TryFromSliceError

§

impl UnwindSafe for kvarn_async::prelude::compact_str::core::ascii::EscapeDefault

§

impl UnwindSafe for BorrowError

§

impl UnwindSafe for BorrowMutError

§

impl UnwindSafe for CharTryFromError

§

impl UnwindSafe for DecodeUtf16Error

§

impl UnwindSafe for kvarn_async::prelude::compact_str::core::char::EscapeDebug

§

impl UnwindSafe for kvarn_async::prelude::compact_str::core::char::EscapeDefault

§

impl UnwindSafe for kvarn_async::prelude::compact_str::core::char::EscapeUnicode

§

impl UnwindSafe for ParseCharError

§

impl UnwindSafe for ToLowercase

§

impl UnwindSafe for ToUppercase

§

impl UnwindSafe for TryFromCharError

§

impl UnwindSafe for CStr

§

impl UnwindSafe for FromBytesUntilNulError

§

impl UnwindSafe for FromBytesWithNulError

§

impl UnwindSafe for SipHasher

§

impl UnwindSafe for ReturnToArg

§

impl UnwindSafe for UnwindActionArg

§

impl UnwindSafe for PhantomPinned

§

impl UnwindSafe for Assume

§

impl UnwindSafe for ParseFloatError

§

impl UnwindSafe for ParseIntError

§

impl UnwindSafe for TryFromIntError

§

impl UnwindSafe for kvarn_async::prelude::compact_str::core::ptr::Alignment

§

impl UnwindSafe for RangeFull

§

impl UnwindSafe for AtomicBool

§

impl UnwindSafe for AtomicI8

§

impl UnwindSafe for AtomicI16

§

impl UnwindSafe for AtomicI32

§

impl UnwindSafe for AtomicI64

§

impl UnwindSafe for AtomicIsize

§

impl UnwindSafe for AtomicU8

§

impl UnwindSafe for AtomicU16

§

impl UnwindSafe for AtomicU32

§

impl UnwindSafe for AtomicU64

§

impl UnwindSafe for AtomicUsize

§

impl UnwindSafe for LocalWaker

§

impl UnwindSafe for RawWaker

§

impl UnwindSafe for RawWakerVTable

§

impl UnwindSafe for Waker

§

impl UnwindSafe for TryFromFloatSecsError

§

impl UnwindSafe for Big8x3

§

impl UnwindSafe for Big32x40

§

impl UnwindSafe for Decoded

§

impl UnwindSafe for FullDecoded

§

impl UnwindSafe for Maybe

§

impl UnwindSafe for NoRuntime

§

impl UnwindSafe for Number

§

impl UnwindSafe for Runtime

§

impl UnwindSafe for Sign

§

impl UnwindSafe for TryCaptureWithDebug

§

impl UnwindSafe for TryCaptureWithoutDebug

§

impl<'a> !UnwindSafe for BorrowedCursor<'a>

§

impl<'a> !UnwindSafe for IoSliceMut<'a>

§

impl<'a> !UnwindSafe for Formatter<'a>

§

impl<'a> !UnwindSafe for ReadBuf<'a>

§

impl<'a> !UnwindSafe for kvarn_async::prelude::compact_str::core::error::Request<'a>

§

impl<'a> !UnwindSafe for Source<'a>

§

impl<'a> !UnwindSafe for ContextBuilder<'a>

§

impl<'a> UnwindSafe for Utf8Pattern<'a>

§

impl<'a> UnwindSafe for PresentArgumentsIter<'a>

§

impl<'a> UnwindSafe for Arguments<'a>

§

impl<'a> UnwindSafe for IoSlice<'a>

§

impl<'a> UnwindSafe for StdinLock<'a>

§

impl<'a> UnwindSafe for Incoming<'a>

§

impl<'a> UnwindSafe for Query<'a>

§

impl<'a> UnwindSafe for QueryPair<'a>

§

impl<'a> UnwindSafe for QueryPairIter<'a>

§

impl<'a> UnwindSafe for ValueQualitySet<'a>

§

impl<'a> UnwindSafe for kvarn_async::prelude::str::Bytes<'a>

§

impl<'a> UnwindSafe for CharIndices<'a>

§

impl<'a> UnwindSafe for Chars<'a>

§

impl<'a> UnwindSafe for EncodeUtf16<'a>

§

impl<'a> UnwindSafe for kvarn_async::prelude::str::EscapeDebug<'a>

§

impl<'a> UnwindSafe for kvarn_async::prelude::str::EscapeDefault<'a>

§

impl<'a> UnwindSafe for kvarn_async::prelude::str::EscapeUnicode<'a>

§

impl<'a> UnwindSafe for kvarn_async::prelude::str::Lines<'a>

§

impl<'a> UnwindSafe for LinesAny<'a>

§

impl<'a> UnwindSafe for SplitAsciiWhitespace<'a>

§

impl<'a> UnwindSafe for SplitWhitespace<'a>

§

impl<'a> UnwindSafe for Utf8Chunk<'a>

§

impl<'a> UnwindSafe for Utf8Chunks<'a>

§

impl<'a> UnwindSafe for kvarn_async::prelude::compact_str::Drain<'a>

§

impl<'a> UnwindSafe for kvarn_async::prelude::compact_str::core::ffi::c_str::Bytes<'a>

§

impl<'a> UnwindSafe for EscapeAscii<'a>

§

impl<'a> UnwindSafe for CharSearcher<'a>

§

impl<'a> UnwindSafe for Context<'a>

§

impl<'a> UnwindSafe for Location<'a>

§

impl<'a> UnwindSafe for PanicInfo<'a>

§

impl<'a> UnwindSafe for PanicMessage<'a>

§

impl<'a> UnwindSafe for Formatted<'a>

§

impl<'a> UnwindSafe for Part<'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, 'b> UnwindSafe for CharSliceSearcher<'a, 'b>

§

impl<'a, 'b> UnwindSafe for StrSearcher<'a, 'b>

§

impl<'a, 'b, const N: usize> UnwindSafe for CharArrayRefSearcher<'a, 'b, N>

§

impl<'a, 'f> !UnwindSafe for VaList<'a, 'f>

§

impl<'a, A> !UnwindSafe for kvarn_async::prelude::compact_str::core::option::IterMut<'a, A>

§

impl<'a, A> UnwindSafe for kvarn_async::prelude::compact_str::core::option::Iter<'a, A>
where A: RefUnwindSafe,

§

impl<'a, B> UnwindSafe for Cow<'a, B>
where <B as ToOwned>::Owned: UnwindSafe, B: RefUnwindSafe + ?Sized,

§

impl<'a, F> UnwindSafe for CharPredicateSearcher<'a, F>
where F: UnwindSafe,

§

impl<'a, I> !UnwindSafe for ByRefSized<'a, I>

§

impl<'a, P> UnwindSafe for MatchIndices<'a, P>
where <P as Pattern>::Searcher<'a>: UnwindSafe,

§

impl<'a, P> UnwindSafe for Matches<'a, P>
where <P as Pattern>::Searcher<'a>: UnwindSafe,

§

impl<'a, P> UnwindSafe for RMatchIndices<'a, P>
where <P as Pattern>::Searcher<'a>: UnwindSafe,

§

impl<'a, P> UnwindSafe for RMatches<'a, P>
where <P as Pattern>::Searcher<'a>: UnwindSafe,

§

impl<'a, P> UnwindSafe for kvarn_async::prelude::str::RSplit<'a, P>
where <P as Pattern>::Searcher<'a>: UnwindSafe,

§

impl<'a, P> UnwindSafe for kvarn_async::prelude::str::RSplitN<'a, P>
where <P as Pattern>::Searcher<'a>: UnwindSafe,

§

impl<'a, P> UnwindSafe for RSplitTerminator<'a, P>
where <P as Pattern>::Searcher<'a>: UnwindSafe,