Struct Revertible

Source
pub struct Revertible<F>
where F: FnOnce() + Send + 'static,
{ /* private fields */ }
Expand description

A revertible action.

Returned by several functions registering callbacks that may have to be unregistered later. This type is marked as must_use to force being explicit about handling reversions.

There several ways to deal with a received Revertible:

  • Call revert_on_unload to automatically revert on addon unload.
  • Call leak or drop it (explicitly or implicitly) to discard and unregister manually.
  • Keep the Revertible and call revert later.
  • Turn it into a callable via into_inner and call it later.

Implementations§

Source§

impl<F> Revertible<F>
where F: FnOnce() + Send + 'static,

Source

pub const fn new(revert: F) -> Self

Creates a new revertible action.

Source

pub fn into_inner(self) -> F

Turns the revertible into the inner callable.

Source

pub fn leak(self)

Leaves the action to not be reverted.

The reversion has to be performed manually. Effectively the same as dropping the revertible.

Source

pub fn revert(self)

Reverts the action.

Source

pub fn revert_on_unload(self)

Submits the revertible to be reverted on unload.

Trait Implementations§

Source§

impl<F> Debug for Revertible<F>
where F: FnOnce() + Send + 'static + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F> From<F> for Revertible<F>
where F: FnOnce() + Send + 'static,

Source§

fn from(revert: F) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<F> Freeze for Revertible<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Revertible<F>
where F: RefUnwindSafe,

§

impl<F> Send for Revertible<F>

§

impl<F> Sync for Revertible<F>
where F: Sync,

§

impl<F> Unpin for Revertible<F>
where F: Unpin,

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.