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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#![warn(missing_docs)]
#![feature(vec_resize_default)]
mod heap_storage;
#[cfg(feature = "mmap")]
mod mmap_storage;
mod value;
mod arena;
mod vector;
mod queue;
mod multi_arena;
pub use heap_storage::HeapStorage;
#[cfg(feature = "mmap")]
pub use mmap_storage::MmapStorage;
pub use value::Value;
pub use arena::{Arena, ArenaIndex};
pub use vector::Vector;
pub use queue::Queue;
pub use multi_arena::{MultiArena, MultiArenaIndex};
pub struct Chunk {
ptr: *mut u8,
len: usize,
_handle_to_drop: Box<dyn std::any::Any>
}
impl ::std::ops::Deref for Chunk {
type Target=[u8];
fn deref(&self) -> &[u8] {
unsafe {std::slice::from_raw_parts(self.ptr, self.len) }
}
}
impl ::std::ops::DerefMut for Chunk {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe { std::slice::from_raw_parts_mut(self.ptr, self.len) }
}
}
pub trait ChunkStorage {
fn create_chunk(&self, ident: Ident, size: usize) -> Chunk;
fn load_or_create_chunk(&self, ident: Ident, size: usize) -> (Chunk, bool);
fn load_chunk(&self, ident: Ident) -> Chunk;
fn forget_chunk(&self, chunk: Chunk);
}
#[derive(Clone)]
pub struct Ident(pub String);
impl Ident {
pub fn sub<T: ::std::fmt::Display>(&self, suffix: T) -> Ident {
Ident(format!("{}_{}", self.0, suffix))
}
}
impl<T: ::std::fmt::Display> From<T> for Ident {
fn from(source: T) -> Self {
Ident(format!("{}", source))
}
}