alopex_embedded/
options.rs1use alopex_core::StorageMode;
4use std::path::Path;
5
6#[derive(Debug, Clone, Default)]
8pub struct DatabaseOptions {
9 memory_mode: bool,
11 memory_limit: Option<usize>,
13}
14
15impl DatabaseOptions {
16 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn in_memory() -> Self {
23 Self {
24 memory_mode: true,
25 memory_limit: None,
26 }
27 }
28
29 pub fn with_memory_limit(mut self, bytes: usize) -> Self {
31 self.memory_mode = true;
32 self.memory_limit = Some(bytes);
33 self
34 }
35
36 pub fn memory_mode(&self) -> bool {
38 self.memory_mode
39 }
40
41 pub fn memory_limit(&self) -> Option<usize> {
43 self.memory_limit
44 }
45
46 pub(crate) fn to_storage_mode(&self, path: Option<&Path>) -> StorageMode {
48 if self.memory_mode {
49 StorageMode::Memory {
50 max_size: self.memory_limit,
51 }
52 } else {
53 let disk_path = path.expect("disk mode requires a path");
54 StorageMode::Disk {
55 path: crate::disk_data_dir_path(disk_path),
56 config: None,
57 }
58 }
59 }
60}