material_dioxus/utils/mod.rs
1// mod weak_component_link;
2// pub use weak_component_link::*;
3
4use std::rc::Rc;
5
6use dioxus::prelude::*;
7
8/// See <https://github.com/DioxusLabs/dioxus/issues/1374>
9#[derive(Clone)]
10pub struct StaticCallback<T> {
11 #[allow(clippy::type_complexity)]
12 inner: Rc<RefCell<Box<dyn FnMut(T)>>>,
13}
14
15impl<T> StaticCallback<T> {
16 pub fn call(&self, arg: T) {
17 (self.inner.borrow_mut())(arg)
18 }
19}
20
21impl<F, T> From<F> for StaticCallback<T>
22where
23 F: FnMut(T) + 'static,
24{
25 fn from(f: F) -> Self {
26 Self {
27 inner: Rc::new(RefCell::new(Box::new(f))),
28 }
29 }
30}