pub struct BailoutGuard<T> { /* private fields */ }Expand description
A guard that ensures a value is dropped even if PHP bailout occurs.
BailoutGuard heap-allocates the wrapped value and registers a cleanup callback.
If a bailout occurs, the cleanup runs before the bailout is re-triggered.
If the guard is dropped normally, the cleanup is cancelled and the value is dropped.
§Performance Note
This incurs a heap allocation. Only use for values that absolutely must be cleaned up (file handles, network connections, locks, etc.). For simple values, the overhead isn’t worth it.
Implementations§
Source§impl<T: 'static> BailoutGuard<T>
impl<T: 'static> BailoutGuard<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Creates a new BailoutGuard wrapping the given value.
The value is heap-allocated and a cleanup callback is registered. If a bailout occurs, the value will be dropped. If this guard is dropped normally, the value is dropped and the cleanup is cancelled.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the guard and returns the wrapped value.
The cleanup callback is cancelled.