From 0660151a8b641fa0a23dde2598132029970f7ae4 Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 11 Feb 2021 12:07:22 +0100 Subject: refactoring - reduced code size by about a third --- src/view/weak_links.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/view/weak_links.rs (limited to 'src/view/weak_links.rs') 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(Rc>>>); + +impl Clone for WeakComponentLink { + fn clone(&self) -> Self { + Self(Rc::clone(&self.0)) + } +} + +impl Default for WeakComponentLink { + fn default() -> Self { + Self(Rc::default()) + } +} + +impl Deref for WeakComponentLink { + type Target = Rc>>>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl PartialEq for WeakComponentLink { + fn eq(&self, other: &Self) -> bool { + Rc::ptr_eq(&self.0, &other.0) + } +} -- cgit v1.2.3