Struct sauron_core::html::attributes::Callback [−][src]
pub struct Callback<EVENT, MSG> { /* fields omitted */ }
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
Trait Implementations
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
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.
This is the best approximation of comparison whether 2 callbacks are equal.
There is no 100% guarante that this is true since we can not compare 2 closures event if they have the same logic.
This is done by comparing the type_id of the input and type_id of the output.
Auto Trait Implementations
impl<EVENT, MSG> !RefUnwindSafe for Callback<EVENT, MSG>
impl<EVENT, MSG> !UnwindSafe for Callback<EVENT, MSG>
Blanket Implementations
Mutably borrows from an owned value. Read more