atom.rs 574 B

12345678910111213141516171819202122232425262728
  1. use crate::{AtomId, AtomRoot, Readable, Writable};
  2. pub type Atom<T> = fn(AtomBuilder) -> T;
  3. pub struct AtomBuilder;
  4. impl<V> Readable<V> for Atom<V> {
  5. fn read(&self, _root: AtomRoot) -> Option<V> {
  6. todo!()
  7. }
  8. fn init(&self) -> V {
  9. (*self)(AtomBuilder)
  10. }
  11. fn unique_id(&self) -> AtomId {
  12. *self as *const ()
  13. }
  14. }
  15. impl<V> Writable<V> for Atom<V> {
  16. fn write(&self, _root: AtomRoot, _value: V) {
  17. todo!()
  18. }
  19. }
  20. #[test]
  21. fn atom_compiles() {
  22. static TEST_ATOM: Atom<&str> = |_| "hello";
  23. dbg!(TEST_ATOM.init());
  24. }