Skip to main content

ComponentEvent

Struct ComponentEvent 

Source
pub struct ComponentEvent<'d, C: 'static, D> { /* private fields */ }
Expand description

A helper type that contains the event target and the event detail.

It implements Deref<ComponentRc<C>> so that any associated function in ComponentRc<C> can be visited.

Implementations§

Source§

impl<'d, C: 'static, D> ComponentEvent<'d, C, D>

Source

pub fn new(rc: ComponentRc<C>, detail: &'d mut D) -> Self

Create with event target and detail.

Source

pub fn rc(&self) -> ComponentRc<C>

Get the target component.

Source

pub fn clone_detail(&self) -> D
where D: Clone,

Clone the event detail.

Source

pub fn detail(&self) -> &D

Get the event detail.

Source

pub fn detail_mut(&mut self) -> &mut D

Get the mutable reference of the event detail.

Methods from Deref<Target = ComponentRc<C>>§

Source

pub fn task<R: 'static>(&self, f: impl 'static + FnOnce(&mut C) -> R)

Schedule an update in another task, getting the component mutable reference.

The f will be called asynchronously. The template is always updated after f being called. Panics if any error occurred during update.

Source

pub fn task_with<R: 'static>( &self, f: impl 'static + FnOnce(&mut C, &mut ComponentMutCtx) -> R, )

Schedule an update in another task, getting the component mutable reference.

The f will be called asynchronously. If the template is needed to be updated, ComponentMutCtx::need_update should be called during f execution. Panics if any error occurred during update.

Source

pub async fn update<R: 'static>( &self, f: impl 'static + FnOnce(&mut C) -> R, ) -> Result<R, Error>

Schedule an update, getting the component mutable reference.

The f will be called asynchronously. The template is always updated after f being called.

Source

pub async fn update_with<R: 'static>( &self, f: impl 'static + FnOnce(&mut C, &mut ComponentMutCtx) -> R, ) -> Result<R, Error>

Schedule a visiting task, getting the component mutable reference.

The f will be called asynchronously. If the template is needed to be updated, ComponentMutCtx::need_update should be called during f execution.

Source

pub async fn get<R: 'static>(&self, f: impl 'static + FnOnce(&C) -> R) -> R

Schedule a visiting task, getting the component reference.

The f will be called asynchronously.

Trait Implementations§

Source§

impl<'d, C: 'static, D> Deref for ComponentEvent<'d, C, D>

Source§

type Target = ComponentRc<C>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'d, C, D> !RefUnwindSafe for ComponentEvent<'d, C, D>

§

impl<'d, C, D> !Send for ComponentEvent<'d, C, D>

§

impl<'d, C, D> !Sync for ComponentEvent<'d, C, D>

§

impl<'d, C, D> !UnwindSafe for ComponentEvent<'d, C, D>

§

impl<'d, C, D> Freeze for ComponentEvent<'d, C, D>

§

impl<'d, C, D> Unpin for ComponentEvent<'d, C, D>

§

impl<'d, C, D> UnsafeUnpin for ComponentEvent<'d, C, D>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.