1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::state_access::{CloneState, StateAccess};
use crate::hooks_state_functions::use_state;
#[topo::nested]
pub fn do_once<F: FnMut() -> ()>(mut func: F) -> StateAccess<bool> {
let has_done = use_state(|| false);
if !has_done.get() {
func();
has_done.set(true);
}
has_done
}
#[derive(Clone,Copy,Debug,PartialEq,Hash,Eq)]
pub struct Local( topo::Id );
impl std::fmt::Display for Local {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:#?}", self.0)
}
}
impl Local{
#[topo::nested]
pub fn new() -> Local{
Local( topo::Id::current())
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct CallSite {
location: usize,
}
impl CallSite {
#[track_caller]
pub fn here() -> Self {
Self {
location: std::panic::Location::caller() as *const _ as usize,
}
}
}