cartel_sqlite/settings/
limits.rs1use std::{num, time};
2
3#[derive(Clone, Copy, PartialEq, Eq)]
4pub struct Limits {
5 pub parameters: Parameters,
6 pub scan: Scan,
7 pub savepoints: usize,
9 pub program: Program,
10 pub work: Work,
11}
12
13#[derive(Clone, Copy, PartialEq, Eq)]
14pub struct Work {
15 pub open: Budget,
18 pub call: Budget,
20 pub cleanup: Progress,
22}
23
24impl Work {
25 pub const fn uniform(budget: Budget) -> Self {
26 Self {
27 open: budget,
28 call: budget,
29 cleanup: budget.progress,
30 }
31 }
32}
33
34#[derive(Clone, Copy, PartialEq, Eq)]
35pub struct Budget {
36 pub progress: Progress,
38 pub busy: Busy,
40}
41
42#[derive(Clone, Copy, PartialEq, Eq)]
43pub struct Parameters {
44 pub items: usize,
45 pub bytes: usize,
46}
47
48#[derive(Clone, Copy, PartialEq, Eq)]
49pub struct Scan {
50 pub rows: usize,
51 pub row_bytes: usize,
52}
53
54#[derive(Clone, Copy, PartialEq, Eq)]
55#[repr(transparent)]
56pub struct Progress(num::NonZero<u64>);
57
58impl Progress {
59 pub const fn new(quanta: num::NonZero<u64>) -> Self {
60 Self(quanta)
61 }
62
63 pub const fn get(self) -> u64 {
64 self.0.get()
65 }
66}
67
68#[derive(Clone, Copy, PartialEq, Eq)]
69#[repr(transparent)]
70pub struct Program(num::NonZero<u32>);
71
72impl Program {
73 pub const fn new(ops: num::NonZero<u32>) -> Self {
74 Self(ops)
75 }
76
77 pub const fn get(self) -> u32 {
78 self.0.get()
79 }
80
81 pub(crate) fn sqlite_ops(self) -> num::NonZero<i32> {
82 self.0
83 .min(num::NonZero::<i32>::MAX.cast_unsigned())
84 .cast_signed()
85 }
86}
87
88#[derive(Clone, Copy, PartialEq, Eq)]
89pub struct Busy {
90 pub window: time::Duration,
92 pub interval: time::Duration,
94 pub retries: num::NonZero<u32>,
96}