diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-17 17:06:48 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-17 17:06:48 +0100 |
commit | cb310a66e94db4e0c4f7d0373a670156b012412a (patch) | |
tree | 501fd4ed17d892d693d4123fffaca8d942144e3b /src/view/weak_links.rs | |
parent | be3367dd2921eb30ae7970d233b83ac3af861952 (diff) | |
parent | 0660151a8b641fa0a23dde2598132029970f7ae4 (diff) | |
download | wasm-card-cb310a66e94db4e0c4f7d0373a670156b012412a.tar.gz wasm-card-cb310a66e94db4e0c4f7d0373a670156b012412a.tar.bz2 |
Merge branch 'main' of codeberg.org:jelemux/wasm-card
Diffstat (limited to 'src/view/weak_links.rs')
-rw-r--r-- | src/view/weak_links.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/view/weak_links.rs b/src/view/weak_links.rs new file mode 100644 index 0000000..689c3c4 --- /dev/null +++ b/src/view/weak_links.rs @@ -0,0 +1,33 @@ +use std::cell::RefCell; +use std::ops::Deref; +use std::rc::Rc; +use yew::prelude::*; + +/// Weak link; Useful for being able to have a list of subcomponents. +pub struct WeakComponentLink<COMP: Component>(Rc<RefCell<Option<ComponentLink<COMP>>>>); + +impl<COMP: Component> Clone for WeakComponentLink<COMP> { + fn clone(&self) -> Self { + Self(Rc::clone(&self.0)) + } +} + +impl<COMP: Component> Default for WeakComponentLink<COMP> { + fn default() -> Self { + Self(Rc::default()) + } +} + +impl<COMP: Component> Deref for WeakComponentLink<COMP> { + type Target = Rc<RefCell<Option<ComponentLink<COMP>>>>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<COMP: Component> PartialEq for WeakComponentLink<COMP> { + fn eq(&self, other: &Self) -> bool { + Rc::ptr_eq(&self.0, &other.0) + } +} |