Skip to main content

UnwindSafe

Trait UnwindSafe 

1.9.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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

1.9.0 · Source§

impl UnwindSafe for Condvar

Source§

impl UnwindSafe for JsFuture

1.59.0 · Source§

impl UnwindSafe for Once

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.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, A> UnwindSafe for Arc<T, A>

1.9.0 · Source§

impl<T, A> UnwindSafe for IntoIter<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,

1.9.0 · Source§

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

1.9.0 · Source§

impl<T> UnwindSafe for &T
where T: RefUnwindSafe + ?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 AssertUnwindSafe<T>

1.9.0 · Source§

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

1.25.0 · Source§

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

1.28.0 · Source§

impl<T> UnwindSafe for NonZero<T>

Source§

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

1.70.0 · Source§

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

Source§

impl<T> UnwindSafe for Receiver<T>

Source§

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

1.9.0 · Source§

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

Source§

impl<T> UnwindSafe for Sender<T>

Auto implementors§

§

impl !UnwindSafe for EuvBadgeProps

§

impl !UnwindSafe for EuvButtonProps

§

impl !UnwindSafe for EuvCameraConfig

§

impl !UnwindSafe for EuvDebugProps

§

impl !UnwindSafe for EuvDropdownProps

§

impl !UnwindSafe for EuvFieldProps

§

impl !UnwindSafe for EuvInputProps

§

impl !UnwindSafe for EuvLogoProps

§

impl !UnwindSafe for EuvMobileNavItemProps

§

impl !UnwindSafe for EuvModalProps

§

impl !UnwindSafe for EuvNavItemProps

§

impl !UnwindSafe for EuvNavItemsProps

§

impl !UnwindSafe for EuvPageRouterProps

§

impl !UnwindSafe for EuvRouteConfig

§

impl !UnwindSafe for EuvRoutesProps

§

impl !UnwindSafe for EuvSidebarItemProps

§

impl !UnwindSafe for EuvSidebarProps

§

impl !UnwindSafe for EuvSliderProps

§

impl !UnwindSafe for EuvTagProps

§

impl !UnwindSafe for EuvUploadProps

§

impl !UnwindSafe for EuvVirtualListProps

§

impl !UnwindSafe for NestedRouteConfig

§

impl UnwindSafe for AlertVariant

§

impl UnwindSafe for Alignment

§

impl UnwindSafe for Console

§

impl UnwindSafe for ConsoleEntry

§

impl UnwindSafe for Counter

§

impl UnwindSafe for DebugAsHex

§

impl UnwindSafe for Duration

§

impl UnwindSafe for Error

§

impl UnwindSafe for ErrorBoundary

§

impl UnwindSafe for ErrorBoundaryPhase

§

impl UnwindSafe for EuvAlertProps

§

impl UnwindSafe for EuvAvatarProps

§

impl UnwindSafe for EuvAvatarSize

§

impl UnwindSafe for EuvBreadcrumbItem

§

impl UnwindSafe for EuvBreadcrumbProps

§

impl UnwindSafe for EuvButtonVariant

§

impl UnwindSafe for EuvCalendarDay

§

impl UnwindSafe for EuvCalendarProps

§

impl UnwindSafe for EuvCalendarWeekday

§

impl UnwindSafe for EuvCameraFacing

§

impl UnwindSafe for EuvCardProps

§

impl UnwindSafe for EuvCheckboxProps

§

impl UnwindSafe for EuvCollapseItem

§

impl UnwindSafe for EuvCollapseProps

§

impl UnwindSafe for EuvDividerOrientation

§

impl UnwindSafe for EuvDividerProps

§

impl UnwindSafe for EuvDocLayoutProps

§

impl UnwindSafe for EuvDrawerProps

§

impl UnwindSafe for EuvDropdownItem

§

impl UnwindSafe for EuvFeature

§

impl UnwindSafe for EuvFeatureGridProps

§

impl UnwindSafe for EuvHeaderProps

§

impl UnwindSafe for EuvHeroAction

§

impl UnwindSafe for EuvHeroActionProps

§

impl UnwindSafe for EuvHeroProps

§

impl UnwindSafe for EuvIconProps

§

impl UnwindSafe for EuvIconSize

§

impl UnwindSafe for EuvInfoProps

§

impl UnwindSafe for EuvLoadingProps

§

impl UnwindSafe for EuvMarkdownProps

§

impl UnwindSafe for EuvMdBlock

§

impl UnwindSafe for EuvMdInline

§

impl UnwindSafe for EuvNavItemConfig

§

impl UnwindSafe for EuvNavbarItem

§

impl UnwindSafe for EuvNavbarLinkProps

§

impl UnwindSafe for EuvNavbarProps

§

impl UnwindSafe for EuvPaginationItem

§

impl UnwindSafe for EuvPaginationProps

§

impl UnwindSafe for EuvPanelProps

§

impl UnwindSafe for EuvPanelVariant

§

impl UnwindSafe for EuvPopoverProps

§

impl UnwindSafe for EuvProgressProps

§

impl UnwindSafe for EuvRadioGroupProps

§

impl UnwindSafe for EuvRadioOption

§

impl UnwindSafe for EuvRatingProps

§

impl UnwindSafe for EuvRatingSize

§

impl UnwindSafe for EuvResultProps

§

impl UnwindSafe for EuvSidebarItem

§

impl UnwindSafe for EuvSkeletonProps

§

impl UnwindSafe for EuvSliderHelpers

§

impl UnwindSafe for EuvSpaceProps

§

impl UnwindSafe for EuvSpaceSize

§

impl UnwindSafe for EuvStatProps

§

impl UnwindSafe for EuvStep

§

impl UnwindSafe for EuvStepsProps

§

impl UnwindSafe for EuvSwitchProps

§

impl UnwindSafe for EuvSwitchState

§

impl UnwindSafe for EuvTabItem

§

impl UnwindSafe for EuvTableAlign

§

impl UnwindSafe for EuvTableColumn

§

impl UnwindSafe for EuvTableProps

§

impl UnwindSafe for EuvTableRow

§

impl UnwindSafe for EuvTabsProps

§

impl UnwindSafe for EuvTagColor

§

impl UnwindSafe for EuvTagVariant

§

impl UnwindSafe for EuvTimelineItem

§

impl UnwindSafe for EuvTimelineProps

§

impl UnwindSafe for EuvTocItem

§

impl UnwindSafe for EuvTocProps

§

impl UnwindSafe for EuvTooltipPlacement

§

impl UnwindSafe for EuvTooltipProps

§

impl UnwindSafe for EuvUploadFile

§

impl UnwindSafe for EuvUploadStatus

§

impl UnwindSafe for EuvVconsoleDrawerProps

§

impl UnwindSafe for EuvVconsoleFabProps

§

impl UnwindSafe for EuvVconsolePanelProps

§

impl UnwindSafe for EuvVirtualListConfig

§

impl UnwindSafe for FormState

§

impl UnwindSafe for FormattingOptions

§

impl UnwindSafe for I18n

§

impl UnwindSafe for LogFilter

§

impl UnwindSafe for LogLevel

§

impl UnwindSafe for LogoButtonVariant

§

impl UnwindSafe for NativeTouchPoint

§

impl UnwindSafe for NativeTouchPointF64

§

impl UnwindSafe for Ordering

§

impl UnwindSafe for ProfileEntry

§

impl UnwindSafe for ProfilerHandle

§

impl UnwindSafe for ProfilerMark

§

impl UnwindSafe for Router

§

impl UnwindSafe for Sign

§

impl UnwindSafe for SystemTime

§

impl UnwindSafe for ThemeState

§

impl UnwindSafe for Toggle

§

impl UnwindSafe for TransitionConfig

§

impl UnwindSafe for TransitionPhase

§

impl UnwindSafe for TransitionState

§

impl UnwindSafe for UseEuvBrowser

§

impl UnwindSafe for UseEuvCamera

§

impl UnwindSafe for UseEuvInput

§

impl UnwindSafe for UseEuvLayout

§

impl UnwindSafe for UseVirtualList

§

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> !UnwindSafe for Formatter<'a>

§

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

§

impl<'b, T> !UnwindSafe for RefMut<'b, T>

§

impl<F> UnwindSafe for FromFn<F>
where F: UnwindSafe,

§

impl<T, L> UnwindSafe for AsyncState<T, L>
where L: UnwindSafe, T: UnwindSafe,

§

impl<T, L> UnwindSafe for UseAsyncHandle<T, L>

§

impl<T, S, A> UnwindSafe for HashSet<T, S, A>
where HashSet<T, S, A>: UnwindSafe,

§

impl<T> !UnwindSafe for LazyComponent<T>

§

impl<T> UnwindSafe for Cell<T>
where UnsafeCell<T>: UnwindSafe, T: ?Sized,

§

impl<T> UnwindSafe for DebouncedValue<T>
where Signal<T>: UnwindSafe, Signal<DebounceState<T>>: UnwindSafe,

§

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

§

impl<T> UnwindSafe for NumBuffer<T>

§

impl<T> UnwindSafe for Previous<T>

§

impl<T> UnwindSafe for RefCell<T>
where UnsafeCell<T>: UnwindSafe, T: ?Sized,

§

impl<T> UnwindSafe for SuspenseHandle<T>

§

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

§

impl<T> UnwindSafe for ThrottledValue<T>

§

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