sqlite_functions/
options.rs1use rusqlite::functions::FunctionFlags;
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum Arity {
6 Exact(u16),
8 Variadic,
10}
11
12impl Arity {
13 pub(crate) const fn as_sqlite(self) -> i32 {
14 match self {
15 Self::Exact(value) => value as i32,
16 Self::Variadic => -1,
17 }
18 }
19}
20
21#[derive(Clone, Debug)]
27pub struct FunctionOptions {
28 name: String,
29 arity: Arity,
30 flags: FunctionFlags,
31}
32
33impl FunctionOptions {
34 #[must_use]
36 pub fn new(name: impl Into<String>, arity: Arity) -> Self {
37 Self {
38 name: name.into(),
39 arity,
40 flags: FunctionFlags::SQLITE_UTF8,
41 }
42 }
43
44 #[must_use]
46 pub fn deterministic(mut self) -> Self {
47 self.flags |= FunctionFlags::SQLITE_DETERMINISTIC;
48 self
49 }
50
51 #[must_use]
53 pub fn innocuous(mut self) -> Self {
54 self.flags |= FunctionFlags::SQLITE_INNOCUOUS;
55 self
56 }
57
58 #[must_use]
60 pub fn direct_only(mut self) -> Self {
61 self.flags |= FunctionFlags::SQLITE_DIRECTONLY;
62 self
63 }
64
65 #[must_use]
67 pub fn with_flags(mut self, flags: FunctionFlags) -> Self {
68 self.flags |= flags;
69 self
70 }
71
72 #[must_use]
74 pub fn name(&self) -> &str {
75 &self.name
76 }
77
78 #[must_use]
80 pub const fn arity(&self) -> Arity {
81 self.arity
82 }
83
84 #[must_use]
86 pub const fn flags(&self) -> FunctionFlags {
87 self.flags
88 }
89
90 pub(crate) fn into_parts(self) -> (String, i32, FunctionFlags) {
91 (self.name, self.arity.as_sqlite(), self.flags)
92 }
93}