1use std::borrow::Borrow;
4use std::cell::RefCell;
5use std::fmt::Display;
6use std::rc::Rc;
7use std::sync::{
8 atomic::{AtomicUsize, Ordering},
9 Arc, Mutex,
10};
11
12pub trait Pointee<T> {
16 fn get(&self) -> T;
18}
19
20impl<T> Pointee<T> for Rc<RefCell<T>>
21where
22 T: Clone,
23{
24 fn get(&self) -> T {
25 RefCell::borrow(self).clone()
26 }
27}
28
29impl<T> Pointee<T> for Arc<Mutex<T>>
30where
31 T: Clone,
32{
33 fn get(&self) -> T {
34 self.lock().unwrap().clone()
35 }
36}
37
38#[derive(Debug)]
40pub struct Borrowed<T>(T);
41
42impl<T, X> Pointee<T> for Borrowed<X>
43where
44 X: Borrow<T>,
45 T: Clone,
46{
47 fn get(&self) -> T {
48 self.0.borrow().clone()
49 }
50}
51
52#[derive(Debug)]
54pub struct Pointer<T>(pub *const T);
55
56impl<T> Pointee<T> for Pointer<T>
57where
58 T: Clone,
59{
60 fn get(&self) -> T {
61 unsafe { &*self.0 }.clone()
62 }
63}
64
65pub trait Expectation: Display {
67 fn type_id(&self) -> usize;
69
70 fn is_ready(&self) -> bool;
74
75 fn set_done(&self);
79
80 fn type_signature(&self) -> &'static str;
82}
83
84pub fn next_type_id() -> usize {
86 NEXT_TYPE_ID.fetch_add(1, Ordering::Relaxed)
87}
88
89static NEXT_TYPE_ID: AtomicUsize = AtomicUsize::new(0);