diff --git a/pagetop/src/core/component/arc.rs b/pagetop/src/core/component/arc.rs index 4c0b0814..c3e5c2cd 100644 --- a/pagetop/src/core/component/arc.rs +++ b/pagetop/src/core/component/arc.rs @@ -2,7 +2,7 @@ use crate::core::component::{ComponentTrait, Context}; use crate::html::{html, Markup}; use crate::{new_handle, Handle, Weight}; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, RwLock, RwLockReadGuard}; new_handle!(COMPONENT_NULL for Crate); @@ -37,10 +37,18 @@ impl ArcComponent { ArcComponent(Arc::new(RwLock::new(component))) } + // ArcComponent BUILDER. + pub fn set(&mut self, component: impl ComponentTrait) { self.0 = Arc::new(RwLock::new(component)); } + // ArcComponent GETTERS. + + pub fn get(&self) -> RwLockReadGuard<'_, dyn ComponentTrait> { + self.0.read().unwrap() + } + pub(crate) fn handle(&self) -> Handle { self.0.read().unwrap().handle() } diff --git a/pagetop/src/core/component/typed.rs b/pagetop/src/core/component/typed.rs index e31acab6..0197645d 100644 --- a/pagetop/src/core/component/typed.rs +++ b/pagetop/src/core/component/typed.rs @@ -2,7 +2,7 @@ use crate::core::component::{ComponentTrait, Context}; use crate::html::{html, Markup}; use crate::{Handle, Weight}; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, RwLock, RwLockReadGuard}; #[derive(Default)] pub struct TypedComponent(Arc>); @@ -22,10 +22,18 @@ impl TypedComponent { TypedComponent(Arc::new(RwLock::new(component))) } + // TypedComponent BUILDER. + pub fn set(&mut self, component: T) { self.0 = Arc::new(RwLock::new(component)); } + // TypedComponent GETTERS. + + pub fn get(&self) -> RwLockReadGuard<'_, T> { + self.0.read().unwrap() + } + pub(crate) fn handle(&self) -> Handle { self.0.read().unwrap().handle() }