nut/consts/
mod.rs

1use std::fmt;
2use std::time::Duration;
3
4// pub(crate) const MAX_ALLOC_SIZE: usize = 0xFFFFFFF;
5pub(crate) const MAX_MAP_SIZE: u64 = 0x0FFF_FFFF;
6
7pub(crate) const MIN_KEYS_PER_PAGE: usize = 2;
8
9#[allow(clippy::upper_case_acronyms)]
10pub(crate) type PGID = u64;
11
12#[allow(clippy::upper_case_acronyms)]
13pub(crate) type TXID = u64;
14
15pub(crate) const MAX_MMAP_STEP: u64 = 1 << 30;
16
17/// database mime header
18pub(crate) const MAGIC: u32 = 0xED0C_DAED;
19
20/// database version
21pub(crate) const VERSION: u32 = 2;
22
23// TODO: openbsd
24pub(crate) const IGNORE_NOSYNC: bool = true;
25
26pub(crate) const DEFAULT_MAX_BATCH_SIZE: usize = 1000;
27
28pub(crate) const DEFAULT_MAX_BATCH_DELAY: Duration = Duration::from_millis(10000);
29// pub(crate) const DEFAULT_ALLOC_SIZE: u64 = 16 * 1024 * 1024;
30
31bitflags! {
32    /// Defines type of the page
33    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
34    pub struct Flags: u16 {
35        /// Either branch or bucket page
36        const BRANCHES = 0b00001;
37        /// Leaf page
38        const LEAVES = 0b00010;
39        /// Meta page
40        const META = 0b00100;
41        /// Freelist page
42        const FREELIST = 0b10000;
43    }
44}
45
46impl fmt::Display for Flags {
47    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48        let d = match *self {
49            Flags::BRANCHES => "branches".to_string(),
50            Flags::LEAVES => "leaves".to_string(),
51            Flags::META => "meta".to_string(),
52            Flags::FREELIST => "freelist".to_string(),
53            _ => panic!("unknown flag"),
54        };
55        write!(f, "{d}")
56    }
57}