scoped_callback

Struct Scope

Source
pub struct Scope<'env> { /* private fields */ }
Expand description

A Scope is used to register callbacks. See Scope::register.

Implementations§

Source§

impl<'env> Scope<'env>

Source

pub fn register<'scope, A: 'static, R: 'static, H: 'static>( &'scope self, c: impl FnMut(A) -> R + 'env, register: impl FnOnce(Box<dyn FnMut(A) -> R>) -> H + 'env, deregister: impl FnOnce(H) + 'env, ) -> Registered<'env, 'scope>

Register the function c with local lifetime 'env using the register and deregister functions that handle only 'static lifetime functions. The returned Registered object will, when dropped, invoke the deregister function.

If the Registered object is std::mem::forget-ed, Scope::drop will perform the de-registration.

Note: If the callback passed to the register function is invoked after deregister has been invoked, the callback will panic!.

Source

pub fn future<'scope>( &'scope self, future: LocalBoxFuture<'env, ()>, ) -> impl Future<Output = ()> + 'static

Wrap a scoped Future into one with a 'static lifetime. Future::poll will panic! if called after the scope has been dropped.

Trait Implementations§

Source§

impl<'env> Drop for Scope<'env>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'env> !Freeze for Scope<'env>

§

impl<'env> !RefUnwindSafe for Scope<'env>

§

impl<'env> !Send for Scope<'env>

§

impl<'env> !Sync for Scope<'env>

§

impl<'env> Unpin for Scope<'env>

§

impl<'env> !UnwindSafe for Scope<'env>

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