sqlite_rs/header/
suggested_cache_size.rs

1use crate::traits::ParseBytes;
2use crate::{impl_name, result::SqliteResult};
3use core::ops::Deref;
4
5/// # Suggested cache size (4 Bytes)
6///
7///  The 4-byte big-endian signed integer at offset 48 is the suggested cache
8/// size in pages for the database file. The value is a suggestion only and
9/// Sqlite is under no obligation to honor it. The absolute value of the integer
10/// is used as the suggested size. The suggested cache size can be set using the
11/// default_cache_size pragma.
12#[derive(Debug, Default)]
13pub struct SuggestedCacheSize(u32);
14impl Deref for SuggestedCacheSize {
15  type Target = u32;
16
17  fn deref(&self) -> &Self::Target {
18    &self.0
19  }
20}
21
22impl_name! {SuggestedCacheSize}
23
24impl ParseBytes for SuggestedCacheSize {
25  const LENGTH_BYTES: usize = 4;
26
27  fn parsing_handler(bytes: &[u8]) -> SqliteResult<Self> {
28    let buf: [u8; Self::LENGTH_BYTES] = bytes.try_into()?;
29
30    let database_size = u32::from_be_bytes(buf);
31
32    Ok(Self(database_size))
33  }
34}