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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use super::*;
use std::mem::forget;
use std::ops::Deref;
use std::ptr;
use std::thread::panicking;
use std::marker::PhantomData;
#[derive(Debug)]
#[allow(missing_copy_implementations)]
pub enum AutocommitOn {}
#[derive(Debug)]
#[allow(missing_copy_implementations)]
pub enum AutocommitOff {}
pub trait AutocommitMode {}
impl AutocommitMode for AutocommitOn {}
impl AutocommitMode for AutocommitOff {}
#[derive(Debug)]
pub struct Connected<'env, AC: AutocommitMode>(HDbc<'env>, PhantomData<AC>);
impl<'env, AC: AutocommitMode> Drop for Connected<'env, AC> {
fn drop(&mut self) {
match self.0.disconnect() {
Success(()) | Info(()) => (),
Error(()) => if !panicking() {
panic!("SQLDisconnect returned error")
},
}
}
}
impl<'env, AC: AutocommitMode> Connected<'env, AC> {
pub fn into_hdbc(self) -> HDbc<'env> {
unsafe {
let hdbc = ptr::read(&self.0);
forget(self);
hdbc
}
}
}
impl<'env, AC: AutocommitMode> Deref for Connected<'env, AC> {
type Target = HDbc<'env>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'env, AC: AutocommitMode> DerefMut for Connected<'env, AC> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<'env, AC: AutocommitMode> HDbcWrapper<'env> for Connected<'env, AC> {
type Handle = Connected<'env, AC>;
fn into_hdbc(self) -> HDbc<'env> {
self.into_hdbc()
}
fn from_hdbc(hdbc: HDbc<'env>) -> Self::Handle {
Connected(hdbc, PhantomData)
}
}