diff --git a/packages/fermi/src/atoms/atom.rs b/packages/fermi/src/atoms/atom.rs index 81e04ce0b..2b99174b5 100644 --- a/packages/fermi/src/atoms/atom.rs +++ b/packages/fermi/src/atoms/atom.rs @@ -3,7 +3,7 @@ use crate::{AtomId, AtomRoot, Readable, Writable}; pub type Atom = fn(AtomBuilder) -> T; pub struct AtomBuilder; -impl Readable for Atom { +impl Readable for Atom { fn read(&self, _root: AtomRoot) -> Option { todo!() } @@ -11,14 +11,11 @@ impl Readable for Atom { (*self)(AtomBuilder) } fn unique_id(&self) -> AtomId { - AtomId { - ptr: *self as *const (), - type_id: std::any::TypeId::of::(), - } + *self as *const () } } -impl Writable for Atom { +impl Writable for Atom { fn write(&self, _root: AtomRoot, _value: V) { todo!() } diff --git a/packages/fermi/src/atoms/atomfamily.rs b/packages/fermi/src/atoms/atomfamily.rs index 29cecd4b2..60fc22bcb 100644 --- a/packages/fermi/src/atoms/atomfamily.rs +++ b/packages/fermi/src/atoms/atomfamily.rs @@ -4,7 +4,7 @@ use im_rc::HashMap as ImMap; pub struct AtomFamilyBuilder; pub type AtomFamily = fn(AtomFamilyBuilder) -> ImMap; -impl Readable> for AtomFamily { +impl Readable> for AtomFamily { fn read(&self, _root: AtomRoot) -> Option> { todo!() } @@ -14,14 +14,11 @@ impl Readable> for AtomFamily { } fn unique_id(&self) -> AtomId { - AtomId { - ptr: *self as *const (), - type_id: std::any::TypeId::of::(), - } + *self as *const () } } -impl Writable> for AtomFamily { +impl Writable> for AtomFamily { fn write(&self, _root: AtomRoot, _value: ImMap) { todo!() } diff --git a/packages/fermi/src/atoms/atomref.rs b/packages/fermi/src/atoms/atomref.rs index c103fa662..59e412031 100644 --- a/packages/fermi/src/atoms/atomref.rs +++ b/packages/fermi/src/atoms/atomref.rs @@ -4,7 +4,7 @@ use std::cell::RefCell; pub struct AtomRefBuilder; pub type AtomRef = fn(AtomRefBuilder) -> T; -impl Readable> for AtomRef { +impl Readable> for AtomRef { fn read(&self, _root: AtomRoot) -> Option> { todo!() } @@ -14,10 +14,7 @@ impl Readable> for AtomRef { } fn unique_id(&self) -> AtomId { - AtomId { - ptr: *self as *const (), - type_id: std::any::TypeId::of::(), - } + *self as *const () } } diff --git a/packages/fermi/src/root.rs b/packages/fermi/src/root.rs index 99e97bfbb..f77930c75 100644 --- a/packages/fermi/src/root.rs +++ b/packages/fermi/src/root.rs @@ -1,21 +1,11 @@ -use std::{ - any::{Any, TypeId}, - cell::RefCell, - collections::HashMap, - rc::Rc, - sync::Arc, -}; +use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc, sync::Arc}; use dioxus_core::ScopeId; use im_rc::HashSet; use crate::Readable; -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct AtomId { - pub ptr: *const (), - pub type_id: TypeId, -} +pub type AtomId = *const (); pub struct AtomRoot { pub atoms: RefCell>, @@ -54,15 +44,7 @@ impl AtomRoot { // initialize the value if it's not already initialized if let Some(slot) = atoms.get_mut(&f.unique_id()) { slot.subscribers.insert(scope); - match slot.value.clone().downcast() { - Ok(res) => res, - Err(e) => panic!( - "Downcasting atom failed: {:?}. Has typeid of {:?} but needs typeid of {:?}", - f.unique_id(), - e.type_id(), - TypeId::of::() - ), - } + slot.value.clone().downcast().unwrap() } else { let value = Rc::new(f.init()); let mut subscribers = HashSet::new();