pub struct ErrorModeGuard { /* private fields */ }Expand description
Holds an installed error mode until it is released.
§Release explicitly on the ordinary path
release reports whether the thread was actually restored.
Dropping the guard instead restores on a best-effort basis and discards
any failure, because a destructor has no caller to report to. That is the
right behaviour while unwinding, where no report could be delivered anyway,
and the wrong behaviour on the ordinary path – so the ordinary path calls
release.
Restoration failure is not fatal here. Contrast impersonation, whose restore failure is fail-fast because returning a shared worker under an unknown identity is a process-wide security failure; leaving a thread with the wrong error mode is a real contamination but not that, and imposing the strictest aspect’s semantics on every aspect is precisely what this crate’s composite exists to avoid.
Implementations§
Source§impl ErrorModeGuard
impl ErrorModeGuard
Sourcepub const fn previous(&self) -> Result<ThreadErrorMode, UnsupportedBits>
pub const fn previous(&self) -> Result<ThreadErrorMode, UnsupportedBits>
The mode this thread had before the guard was installed.
§Errors
Returns UnsupportedBits in the same unreachable-by-measurement case
as ThreadErrorMode::capture. The guard itself keeps the raw value, so
restoration round-trips exactly whatever Windows reported, whether or not
this crate’s type can name it.
Sourcepub fn release(self) -> Result<(), RestoreError>
pub fn release(self) -> Result<(), RestoreError>
Restore the thread’s entry mode, reporting whether it worked.
§Errors
Returns RestoreError if Windows refused, leaving the thread
contaminated with whatever was installed.