modelvault_core/config.rs
1//! Open and recovery options for [`crate::db::Database`].
2
3/// How to open a database when the append log tail may be torn or hold an uncommitted transaction.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum RecoveryMode {
6 /// Truncate the store to the last committed prefix (see `docs/migration_0.7_to_0.8.md`).
7 AutoTruncate,
8 /// Return [`crate::error::FormatError::UncleanLogTail`] if the tail is not fully committed.
9 Strict,
10}
11
12/// Open mode for on-disk databases.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum OpenMode {
15 /// Read-only handle; does not create files and does not write.
16 ReadOnly,
17 /// Read/write handle; creates the file if missing.
18 ReadWrite,
19}
20
21/// Options for [`crate::db::Database::open_with_options`] and in-memory open helpers.
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub struct OpenOptions {
24 pub recovery: RecoveryMode,
25 pub mode: OpenMode,
26}
27
28impl Default for OpenOptions {
29 fn default() -> Self {
30 Self {
31 recovery: RecoveryMode::AutoTruncate,
32 mode: OpenMode::ReadWrite,
33 }
34 }
35}