1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::ptr::NonNull;
use libsqlite3_sys::{sqlite3, sqlite3_close, SQLITE_OK};
use crate::sqlite::SqliteError;
#[derive(Debug)]
pub(crate) struct ConnectionHandle(pub(super) NonNull<sqlite3>);
unsafe impl Send for ConnectionHandle {}
impl ConnectionHandle {
#[inline]
pub(super) unsafe fn new(ptr: *mut sqlite3) -> Self {
Self(NonNull::new_unchecked(ptr))
}
#[inline]
pub(crate) fn as_ptr(&self) -> *mut sqlite3 {
self.0.as_ptr()
}
}
impl Drop for ConnectionHandle {
fn drop(&mut self) {
unsafe {
let status = sqlite3_close(self.0.as_ptr());
if status != SQLITE_OK {
panic!("{}", SqliteError::new(self.0.as_ptr()));
}
}
}
}