Struct Callback

Source
pub struct Callback<IN, OUT> { /* private fields */ }
Expand description

A generic sized representation of a function that can be attached to a Node. The callback will essentially be owned by the element

Limitations: The callback takes an Fn instead of FnMut, therefore it can not mutate the environment variables

In effect callbacks attached to DOM events are limited to only passing an OUT to the program and not complex statements.

Note: It would have been nice to have the inner value be Rc<FnMut(IN) -> OUT> +'a but there are a lot of issues that this becomes infeasible: 1 - wasm_bindgen::Closure requires that ’static references to the closure 2 - Accessing Rc::get_mut requires that there is no other Rc or Weak references else where. - We could be iterating on the elements for recursively setting the attributes which is not allowed to have recursive mutable iteration - Attributes of the same name are merged therefore cloning the attributes, hence the callback is necessary.

Implementations§

Source§

impl<IN, OUT> Callback<IN, OUT>
where IN: 'static, OUT: 'static,

Source

pub fn emit(&self, input: IN) -> OUT

This method calls the actual callback.

Source

pub fn map_msg<F, MSG2>(self, cb2: F) -> Callback<IN, MSG2>
where F: Fn(OUT) -> MSG2 + Clone + 'static, MSG2: 'static,

map this Callback msg such that Callback<IN, OUT> becomes Callback<IN, MSG2> Note: the original func_type_id is preserved here

Trait Implementations§

Source§

impl<IN, OUT> Clone for Callback<IN, OUT>

Note: using the #[derive(Clone)] needs IN and OUT to also be Clone

The reason this is manually implemented is, so that IN and OUT doesn’t need to be Clone as it is part of the Callback objects and cloning here is just cloning the pointer of the actual callback function

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<IN, OUT> Debug for Callback<IN, OUT>

Note: using the #[derive(Debug)] needs IN and OUT to also be Debug

The reason this is manually implemented is, so that IN and OUT doesn’t need to be Debug as it is part of the Callback objects and are not shown.

Source§

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

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

impl<MSG> From<Callback<Event, MSG>> for AttributeValue<MSG>

Source§

fn from(listener: EventCallback<MSG>) -> Self

Converts to this type from the input type.
Source§

impl<IN, F, OUT> From<F> for Callback<IN, OUT>
where F: FnMut(IN) -> OUT + 'static, OUT: 'static, IN: 'static,

Source§

fn from(func: F) -> Self

Converts to this type from the input type.
Source§

impl<IN, OUT> PartialEq for Callback<IN, OUT>

Compare if the callbacks are equal Note, we are only comparing the type_id of the function, the input and the output

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<IN, OUT> Freeze for Callback<IN, OUT>

§

impl<IN, OUT> !RefUnwindSafe for Callback<IN, OUT>

§

impl<IN, OUT> !Send for Callback<IN, OUT>

§

impl<IN, OUT> !Sync for Callback<IN, OUT>

§

impl<IN, OUT> Unpin for Callback<IN, OUT>

§

impl<IN, OUT> !UnwindSafe for Callback<IN, OUT>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.