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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
pub mod errors;
mod commands;
mod types;
use self::errors::Error;
use indexmap::IndexMap;
#[doc(hidden)]
pub use protobuf::repeated::RepeatedField;
#[doc(hidden)]
pub use ql2::proto::{Datum, Datum_DatumType as DT, Term, Term_TermType as TT};
use serde::de::DeserializeOwned;
use serde_json::Value;
#[cfg(feature = "tls")]
use native_tls::TlsConnectorBuilder;
use std::net::{TcpStream, SocketAddr};
use std::time::Duration;
use uuid::Uuid;
use futures::sync::mpsc::{Sender, Receiver};
use serde_derive::{Serialize, Deserialize};
pub const DEFAULT_PORT: u16 = 28015;
pub type Result<T> = ::std::result::Result<T, Error>;
#[derive(Clone)]
pub struct Arg {
string: String,
term: Result<Term>,
pool: Option<Connection>,
}
#[derive(Debug)]
pub struct Response<T: DeserializeOwned + Send> {
done: bool,
rx: Receiver<Result<Option<Document<T>>>>,
}
#[derive(Debug)]
struct Request< T: DeserializeOwned + Send + std::fmt::Debug> {
term: Term,
opts: Term,
pool: r2d2::Pool<SessionManager>,
cfg: InnerConfig,
tx: Sender<Result<Option<Document<T>>>>,
write: bool,
retry: bool,
}
struct Session {
id: u64,
broken: bool,
stream: TcpStream,
}
#[derive(Debug, Clone)]
pub struct Config<'a> {
pub servers: Vec<SocketAddr>,
pub db: &'a str,
pub user: &'a str,
pub password: &'a str,
retries: u64,
#[cfg(feature = "tls")]
pub tls: Option<TlsConnectorBuilder>,
}
#[derive(Debug,Clone)]
struct InnerConfig {
cluster: IndexMap<String, Server>,
opts: Opts,
}
#[derive(Debug, Clone, Copy)]
struct SessionManager(Connection);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Connection(Uuid);
#[derive(Debug, Clone, Eq)]
struct Server {
name: String,
addresses: Vec<SocketAddr>,
latency: Duration,
}
#[derive(Debug, Clone)]
struct Opts {
db: String,
user: String,
password: String,
retries: u64,
reproducible: bool,
#[cfg(feature = "tls")]
tls: Option<TlsConnectorBuilder>,
}
#[must_use]
#[derive(Debug, Clone)]
pub struct Client {
term: Result<Term>,
query: String,
write: bool,
}
#[derive(Debug, Clone)]
pub enum Document<T: DeserializeOwned + Send> {
Expected(T),
Unexpected(Value),
}
#[derive(Serialize, Deserialize, Debug)]
struct ReqlResponse {
t: i32,
e: Option<i32>,
r: Value,
b: Option<Value>,
p: Option<Value>,
n: Option<Value>,
}
pub trait IntoArg {
fn into_arg(self) -> Arg;
}
pub trait Run<A: IntoArg> {
fn run<T: DeserializeOwned + Send + std::fmt::Debug + 'static>(&self, args: A) -> Result<Response<T>>;
}