1pub(crate) mod param_cache;
3mod small_cstr;
4pub(crate) use param_cache::ParamIndexCache;
5pub(crate) use small_cstr::SmallCString;
6
7mod sqlite_string;
9pub(crate) use sqlite_string::{alloc, SqliteMallocString};
10
11#[cfg(any(
12 feature = "collation",
13 feature = "functions",
14 feature = "vtab",
15 feature = "pointer"
16))]
17pub(crate) unsafe extern "C" fn free_boxed_value<T>(p: *mut std::ffi::c_void) {
18 drop(Box::from_raw(p.cast::<T>()));
19}
20
21use crate::Result;
22use std::ffi::CStr;
23
24pub enum Named<'a> {
25 Small(SmallCString),
26 C(&'a CStr),
27}
28impl std::ops::Deref for Named<'_> {
29 type Target = CStr;
30 #[inline]
31 fn deref(&self) -> &CStr {
32 match self {
33 Named::Small(s) => s.as_cstr(),
34 Named::C(s) => s,
35 }
36 }
37}
38
39pub trait Name: std::fmt::Debug {
41 fn as_cstr(&self) -> Result<Named<'_>>;
43}
44impl Name for &str {
45 fn as_cstr(&self) -> Result<Named<'_>> {
46 let ss = SmallCString::new(self)?;
47 Ok(Named::Small(ss))
48 }
49}
50impl Name for &CStr {
51 #[inline]
52 fn as_cstr(&self) -> Result<Named<'_>> {
53 Ok(Named::C(self))
54 }
55}