use crate::{AtomId, AtomRoot, Readable, Writable}; pub struct Atom(pub fn(AtomBuilder) -> T); pub struct AtomBuilder; impl Readable for &'static Atom { fn read(&self, _root: AtomRoot) -> Option { todo!() } fn init(&self) -> V { self.0(AtomBuilder) } fn unique_id(&self) -> AtomId { *self as *const Atom as *const () } } impl Writable for &'static Atom { fn write(&self, _root: AtomRoot, _value: V) { todo!() } } #[test] fn atom_compiles() { static TEST_ATOM: Atom<&str> = Atom(|_| "hello"); dbg!((&TEST_ATOM).init()); } #[test] fn atom_is_unique() { static TEST_ATOM_1: Atom<&str> = Atom(|_| "hello"); static TEST_ATOM_2: Atom<&str> = Atom(|_| "hello"); assert_eq!((&TEST_ATOM_1).unique_id(), (&TEST_ATOM_1).unique_id()); assert_ne!((&TEST_ATOM_1).unique_id(), (&TEST_ATOM_2).unique_id()); } #[test] fn atom_is_unique_2() { struct S(String); static TEST_ATOM_1: Atom> = Atom(|_| Vec::new()); static TEST_ATOM_2: Atom> = Atom(|_| Vec::new()); assert_ne!((&TEST_ATOM_1).unique_id(), (&TEST_ATOM_2).unique_id()); }