fix: use typeid of atoms for their unique ID (#558)

This commit is contained in:
Jon Kelley authored and GitHub committed 2022-09-17 10:50:05 -07:00
1 parent 540e785d8b
commit bf9901a6cd
4 files changed
+38 -11

No files matched your search

+6 -3
View File
@@ -3,7 +3,7 @@ use crate::{AtomId, AtomRoot, Readable, Writable};
pub type Atom<T> = fn(AtomBuilder) -> T;
pub struct AtomBuilder;
impl<V> Readable<V> for Atom<V> {
impl<V: 'static> Readable<V> for Atom<V> {
fn read(&self, _root: AtomRoot) -> Option<V> {
todo!()
}
@@ -11,11 +11,14 @@ impl<V> Readable<V> for Atom<V> {
(*self)(AtomBuilder)
}
fn unique_id(&self) -> AtomId {
*self as *const ()
AtomId {
ptr: *self as *const (),
type_id: std::any::TypeId::of::<V>(),
}
}
}
impl<V> Writable<V> for Atom<V> {
impl<V: 'static> Writable<V> for Atom<V> {
fn write(&self, _root: AtomRoot, _value: V) {
todo!()
}
+6 -3
View File
@@ -4,7 +4,7 @@ use im_rc::HashMap as ImMap;
pub struct AtomFamilyBuilder;
pub type AtomFamily<K, V> = fn(AtomFamilyBuilder) -> ImMap<K, V>;
impl<K, V> Readable<ImMap<K, V>> for AtomFamily<K, V> {
impl<K, V: 'static> Readable<ImMap<K, V>> for AtomFamily<K, V> {
fn read(&self, _root: AtomRoot) -> Option<ImMap<K, V>> {
todo!()
}
@@ -14,11 +14,14 @@ impl<K, V> Readable<ImMap<K, V>> for AtomFamily<K, V> {
}
fn unique_id(&self) -> AtomId {
*self as *const ()
AtomId {
ptr: *self as *const (),
type_id: std::any::TypeId::of::<V>(),
}
}
}
impl<K, V> Writable<ImMap<K, V>> for AtomFamily<K, V> {
impl<K, V: 'static> Writable<ImMap<K, V>> for AtomFamily<K, V> {
fn write(&self, _root: AtomRoot, _value: ImMap<K, V>) {
todo!()
}
+5 -2
View File
@@ -4,7 +4,7 @@ use std::cell::RefCell;
pub struct AtomRefBuilder;
pub type AtomRef<T> = fn(AtomRefBuilder) -> T;
impl<V> Readable<RefCell<V>> for AtomRef<V> {
impl<V: 'static> Readable<RefCell<V>> for AtomRef<V> {
fn read(&self, _root: AtomRoot) -> Option<RefCell<V>> {
todo!()
}
@@ -14,7 +14,10 @@ impl<V> Readable<RefCell<V>> for AtomRef<V> {
}
fn unique_id(&self) -> AtomId {
*self as *const ()
AtomId {
ptr: *self as *const (),
type_id: std::any::TypeId::of::<V>(),
}
}
}