sqlite_rs/header/
incremental_vacuum_settings.rs1use crate::traits::ParseBytes;
2use crate::{impl_name, result::SqliteResult};
3use core::ops::Deref;
4
5#[derive(Debug, Default)]
18pub struct IncrementalVacuumSettings {
19 pub largest_root_btree_page: LargestRootBtreePage,
20 pub incremental_vacuum_mode: IncrementalVacuumMode,
21}
22
23impl IncrementalVacuumSettings {
29 pub fn largest_root_btree_page(&self) -> &LargestRootBtreePage {
30 &self.largest_root_btree_page
31 }
32
33 pub fn incremental_vacuum_mode(&self) -> &IncrementalVacuumMode {
34 &self.incremental_vacuum_mode
35 }
36}
37
38#[derive(Debug, Default)]
42pub struct LargestRootBtreePage(u32);
43
44impl Deref for LargestRootBtreePage {
45 type Target = u32;
46
47 fn deref(&self) -> &Self::Target {
48 &self.0
49 }
50}
51
52impl_name! {LargestRootBtreePage}
53
54impl ParseBytes for LargestRootBtreePage {
55 const LENGTH_BYTES: usize = 4;
56
57 fn parsing_handler(bytes: &[u8]) -> SqliteResult<Self> {
58 let buf: [u8; Self::LENGTH_BYTES] = bytes.try_into()?;
59
60 let value = u32::from_be_bytes(buf);
61
62 Ok(Self(value))
63 }
64}
65
66#[derive(Debug, Default)]
69pub enum IncrementalVacuumMode {
70 #[default]
71 False,
72 True,
73}
74impl From<&IncrementalVacuumMode> for bool {
75 fn from(value: &IncrementalVacuumMode) -> Self {
76 match value {
77 IncrementalVacuumMode::True => true,
78 IncrementalVacuumMode::False => false,
79 }
80 }
81}
82impl From<&IncrementalVacuumMode> for u32 {
83 fn from(value: &IncrementalVacuumMode) -> Self {
84 match value {
85 IncrementalVacuumMode::True => 1,
86 IncrementalVacuumMode::False => 0,
87 }
88 }
89}
90
91impl_name! {IncrementalVacuumMode}
92
93impl ParseBytes for IncrementalVacuumMode {
94 const LENGTH_BYTES: usize = 4;
95
96 fn parsing_handler(bytes: &[u8]) -> SqliteResult<Self> {
97 let buf: [u8; Self::LENGTH_BYTES] = bytes.try_into()?;
98
99 let number = u32::from_be_bytes(buf);
100 let value = if number > 0 { Self::True } else { Self::False };
101
102 Ok(value)
103 }
104}