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
use crate::rt;
pub use std::alloc::Layout;
pub unsafe fn alloc(layout: Layout) -> *mut u8 {
let ptr = std::alloc::alloc(layout);
rt::alloc(ptr);
ptr
}
pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
rt::dealloc(ptr);
std::alloc::dealloc(ptr, layout)
}
#[derive(Debug)]
pub struct Track<T> {
value: T,
obj: rt::Allocation,
}
impl<T> Track<T> {
pub fn new(value: T) -> Track<T> {
Track {
value,
obj: rt::Allocation::new(),
}
}
pub fn get_ref(&self) -> &T {
&self.value
}
pub fn get_mut(&mut self) -> &mut T {
&mut self.value
}
pub fn into_inner(self) -> T {
self.value
}
}