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
use rusqlite::{Connection, Savepoint, Transaction};

/// Simple trait to work around:
/// * AsRef isn't implemented for T, so Connection couldn't be owned.
/// * Deref doesn't work automatically for references, so &Savepoint won't work
/// * Borrow would work, but it's not implemented for Savepoint or Transaction
/// This is similar to Savepointable, but works immutably and doesn't care about
/// making savepoints.
pub trait AsConnection {
    fn as_connection(&self) -> &Connection;
}

impl AsConnection for Connection {
    fn as_connection(&self) -> &Connection {
        self
    }
}

impl AsConnection for &Connection {
    fn as_connection(&self) -> &Connection {
        *self
    }
}

impl AsConnection for Transaction<'_> {
    fn as_connection(&self) -> &Connection {
        &*self
    }
}
impl AsConnection for &Transaction<'_> {
    fn as_connection(&self) -> &Connection {
        &*self
    }
}

impl AsConnection for Savepoint<'_> {
    fn as_connection(&self) -> &Connection {
        &*self
    }
}
impl AsConnection for &Savepoint<'_> {
    fn as_connection(&self) -> &Connection {
        &*self
    }
}