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
58
59
60
61
62
63
/// ```compile_fail,E0505
/// use toast_cell::{type_factory::unique, GhostCell, GhostToken};
///
/// let token = GhostToken::new(unique!());
/// let cell = GhostCell::new(1);
///
/// let borrow = cell.borrow(&token);
/// core::mem::drop(token);
/// assert_eq!(*borrow, 1);
/// ```
/// ```compile_fail,E0502
/// use toast_cell::{type_factory::unique, GhostCell, GhostToken};
///
/// let mut token = GhostToken::new(unique!());
/// let cell1 = GhostCell::new(0);
/// let cell2 = GhostCell::new(2);
///
/// let borrow1 = cell1.borrow_mut(&mut token);
/// let borrow2 = cell2.borrow(&token);
/// assert_eq!(*borrow2, 2);
///
/// *borrow1 += 1;
/// ```
/// ```compile_fail,E0505
/// use toast_cell::{type_factory::unique, GhostCell, GhostToken};
///
/// let token = GhostToken::new(unique!());
/// let cell = GhostCell::new(1);
///
/// let borrow = cell.borrow(&token);
/// core::mem::drop(cell);
/// assert_eq!(*borrow, 1);
/// ```
/// ```compile_fail,E0505
/// use toast_cell::{type_factory::unique, GhostCell, GhostToken};
///
/// let mut token = GhostToken::new(unique!());
/// let cell = GhostCell::new(0);
///
/// let borrow = cell.borrow_mut(&mut token);
/// core::mem::drop(cell);
/// *borrow += 1;
/// ```
/// ```compile_fail,E0502
/// use toast_cell::{type_factory::unique, GhostCell, GhostToken};
///
/// let mut value = [1, 2, 3];
/// let cell = GhostCell::from_mut(&mut value);
/// assert_eq!(value, [1, 2, 3]);
///
/// // Appease the typechecker.
/// let token = GhostToken::new(unique!());
/// let _ = cell.borrow(&token);
/// ```