sqlite_collections/db/
as_connection.rs

1use rusqlite::{Connection, Savepoint, Transaction};
2
3/// Simple trait to work around:
4/// * AsRef isn't implemented for T, so Connection couldn't be owned.
5/// * Deref doesn't work automatically for references, so &Savepoint won't work
6/// * Borrow would work, but it's not implemented for Savepoint or Transaction
7/// This is similar to Savepointable, but works immutably and doesn't care about
8/// making savepoints.
9pub trait AsConnection {
10    fn as_connection(&self) -> &Connection;
11}
12
13impl AsConnection for Connection {
14    fn as_connection(&self) -> &Connection {
15        self
16    }
17}
18
19impl AsConnection for &Connection {
20    fn as_connection(&self) -> &Connection {
21        *self
22    }
23}
24
25impl AsConnection for Transaction<'_> {
26    fn as_connection(&self) -> &Connection {
27        &*self
28    }
29}
30impl AsConnection for &Transaction<'_> {
31    fn as_connection(&self) -> &Connection {
32        &*self
33    }
34}
35
36impl AsConnection for Savepoint<'_> {
37    fn as_connection(&self) -> &Connection {
38        &*self
39    }
40}
41impl AsConnection for &Savepoint<'_> {
42    fn as_connection(&self) -> &Connection {
43        &*self
44    }
45}