Struct Callback

Source
pub struct Callback<EVENT, MSG>(/* 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 MSG to the program and not complex statements.

Note: It would have been nice to have the inner value be Rc<FnMut(EVENT) -> MSG> +'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<EVENT, MSG> Callback<EVENT, MSG>
where EVENT: 'static, MSG: 'static,

Source

pub fn emit<T>(&self, value: T) -> MSG
where T: Into<EVENT>,

This method calls the actual callback.

Source

pub fn map_callback<MSG2>( self, cb: Callback<MSG, MSG2>, ) -> Callback<EVENT, MSG2>
where MSG2: 'static,

map this callback using another callback such that MSG becomes MSG2

Trait Implementations§

Source§

impl<EVENT, MSG> Clone for Callback<EVENT, MSG>

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

The reason this is manually implemented is, so that EVENT and MSG 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) -> Callback<EVENT, MSG>

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<EVENT, MSG> Debug for Callback<EVENT, MSG>

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

The reason this is manually implemented is, so that EVENT and MSG 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<(), Error>

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

impl<EVENT, F, MSG> From<F> for Callback<EVENT, MSG>
where F: Fn(EVENT) -> MSG + 'static,

Source§

fn from(func: F) -> Callback<EVENT, MSG>

Converts to this type from the input type.
Source§

impl<EVENT, MSG> PartialEq for Callback<EVENT, MSG>

Note: using the #[derive(PartialEq)] needs EVENT and MSG to also be PartialEq.

The reason this is manually implemented is, so that EVENT and MSG doesn’t need to be PartialEq as it is part of the Callback objects and are not compared

Note: There is no 2 closures are equal, even if they are logically the same. We return true here so as to not make a diff for the callback attribute. Replacing the callback function for each view call is in-efficient.

Source§

fn eq(&self, _rhs: &Callback<EVENT, MSG>) -> 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<EVENT, MSG> Freeze for Callback<EVENT, MSG>

§

impl<EVENT, MSG> !RefUnwindSafe for Callback<EVENT, MSG>

§

impl<EVENT, MSG> !Send for Callback<EVENT, MSG>

§

impl<EVENT, MSG> !Sync for Callback<EVENT, MSG>

§

impl<EVENT, MSG> Unpin for Callback<EVENT, MSG>

§

impl<EVENT, MSG> !UnwindSafe for Callback<EVENT, MSG>

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.