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§
Trait Implementations§
Source§impl<IN, OUT> Clone for Callback<IN, OUT>
Note:
using the #[derive(Clone)] needs IN and OUT to also be Clone
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§impl<IN, OUT> Debug for Callback<IN, OUT>
Note:
using the #[derive(Debug)] needs IN and OUT to also be Debug
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.