feat: use arc instead
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-25 13:58:13 +02:00
parent 10a56ad690
commit af57ef6cc8
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394

View File

@ -1,4 +1,4 @@
use std::rc::Rc; use std::sync::Arc;
pub trait Component { pub trait Component {
fn name(&self) -> String; fn name(&self) -> String;
@ -27,11 +27,11 @@ pub trait Component {
#[derive(Clone)] #[derive(Clone)]
pub struct ConcreteComponent { pub struct ConcreteComponent {
inner: Rc<dyn Component + 'static>, inner: Arc<dyn Component + 'static>,
} }
impl std::ops::Deref for ConcreteComponent { impl std::ops::Deref for ConcreteComponent {
type Target = Rc<dyn Component + 'static>; type Target = Arc<dyn Component + 'static>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.inner &self.inner
@ -40,7 +40,7 @@ impl std::ops::Deref for ConcreteComponent {
impl ConcreteComponent { impl ConcreteComponent {
pub fn new<T: Component + 'static>(t: T) -> Self { pub fn new<T: Component + 'static>(t: T) -> Self {
Self { inner: Rc::new(t) } Self { inner: Arc::new(t) }
} }
} }