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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
use cassandra::collection::Set;
use cassandra::data_type::ConstDataType;
use cassandra::data_type::DataType;
use cassandra::inet::Inet;
use cassandra::user_type::UserType;
use cassandra::util::Protected;
use cassandra::uuid::Uuid;
use cassandra::error::*;
use cassandra_sys::CassTuple as _Tuple;
use cassandra_sys::cass_false;
use cassandra_sys::cass_true;
use cassandra_sys::cass_tuple_data_type;
use cassandra_sys::cass_tuple_free;
use cassandra_sys::cass_tuple_new;
use cassandra_sys::cass_tuple_new_from_data_type;
use cassandra_sys::cass_tuple_set_bool;
use cassandra_sys::cass_tuple_set_bytes;
use cassandra_sys::cass_tuple_set_collection;
use cassandra_sys::cass_tuple_set_decimal;
use cassandra_sys::cass_tuple_set_double;
use cassandra_sys::cass_tuple_set_float;
use cassandra_sys::cass_tuple_set_inet;
use cassandra_sys::cass_tuple_set_int16;
use cassandra_sys::cass_tuple_set_int32;
use cassandra_sys::cass_tuple_set_int64;
use cassandra_sys::cass_tuple_set_int8;
use cassandra_sys::cass_tuple_set_null;
use cassandra_sys::cass_tuple_set_string;
use cassandra_sys::cass_tuple_set_tuple;
use cassandra_sys::cass_tuple_set_uint32;
use cassandra_sys::cass_tuple_set_user_type;
use cassandra_sys::cass_tuple_set_uuid;
use std::ffi::CString;
use std::net::IpAddr;
#[derive(Debug)]
pub struct Tuple(*mut _Tuple);
unsafe impl Send for Tuple {}
impl Protected<*mut _Tuple> for Tuple {
fn inner(&self) -> *mut _Tuple { self.0 }
fn build(inner: *mut _Tuple) -> Self { Tuple(inner) }
}
impl Tuple {
pub fn new(item_count: usize) -> Self { unsafe { Tuple(cass_tuple_new(item_count)) } }
pub fn new_from_data_type(data_type: DataType) -> Tuple {
unsafe { Tuple(cass_tuple_new_from_data_type(data_type.inner())) }
}
pub fn data_type(&mut self) -> ConstDataType { unsafe { ConstDataType(cass_tuple_data_type(self.0)) } }
pub fn set_null(&mut self, index: usize) -> Result<&mut Self> {
unsafe {
cass_tuple_set_null(self.0, index)
.to_result(self)
}
}
pub fn set_int8(&mut self, index: usize, value: i8) -> Result<&mut Self> {
unsafe {
cass_tuple_set_int8(self.0, index, value)
.to_result(self)
}
}
pub fn set_int16(&mut self, index: usize, value: i16) -> Result<&mut Self> {
unsafe {
cass_tuple_set_int16(self.0, index, value)
.to_result(self)
}
}
pub fn set_int32(&mut self, index: usize, value: i32) -> Result<&mut Self> {
unsafe {
cass_tuple_set_int32(self.0, index, value)
.to_result(self)
}
}
pub fn set_uint32(&mut self, index: usize, value: u32) -> Result<&mut Self> {
unsafe {
cass_tuple_set_uint32(self.0, index, value)
.to_result(self)
}
}
pub fn set_int64(&mut self, index: usize, value: i64) -> Result<&mut Self> {
unsafe {
cass_tuple_set_int64(self.0, index, value)
.to_result(self)
}
}
pub fn set_float(&mut self, index: usize, value: f32) -> Result<&mut Self> {
unsafe {
cass_tuple_set_float(self.0, index, value)
.to_result(self)
}
}
pub fn set_double(&mut self, index: usize, value: f64) -> Result<&mut Self> {
unsafe {
cass_tuple_set_double(self.0, index, value)
.to_result(self)
}
}
pub fn set_bool(&mut self, index: usize, value: bool) -> Result<&mut Self> {
unsafe {
cass_tuple_set_bool(self.0, index, if value { cass_true } else { cass_false })
.to_result(self)
}
}
pub fn set_string<S>(&mut self, index: usize, value: S) -> Result<&mut Self>
where S: Into<String> {
unsafe {
let value_cstr = CString::new(value.into())?;
cass_tuple_set_string(self.0,
index,
value_cstr.as_ptr())
.to_result(self)
}
}
pub fn set_bytes(&mut self, index: usize, value: Vec<u8>) -> Result<&mut Self> {
unsafe {
cass_tuple_set_bytes(self.0, index, value.as_ptr(), value.len())
.to_result(self)
}
}
pub fn set_uuid<S>(&mut self, index: usize, value: S) -> Result<&mut Self>
where S: Into<Uuid> {
unsafe {
cass_tuple_set_uuid(self.0, index, value.into().inner())
.to_result(self)
}
}
pub fn set_inet(&mut self, index: usize, value: IpAddr) -> Result<&mut Self> {
let inet = Inet::from(&value);
unsafe {
cass_tuple_set_inet(self.0, index, inet.inner())
.to_result(self)
}
}
pub fn set_collection<S>(&mut self, index: usize, value: S) -> Result<&mut Self>
where S: Into<Set> {
unsafe {
cass_tuple_set_collection(self.0, index, value.into().inner())
.to_result(self)
}
}
pub fn set_tuple(&mut self, index: usize, value: Tuple) -> Result<&mut Self> {
unsafe {
cass_tuple_set_tuple(self.0, index, value.0)
.to_result(self)
}
}
pub fn set_user_type(&mut self, index: usize, value: &UserType) -> Result<&mut Self> {
unsafe {
cass_tuple_set_user_type(self.0, index, value.inner())
.to_result(self)
}
}
}
impl Drop for Tuple {
fn drop(&mut self) { unsafe { cass_tuple_free(self.0) } }
}