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
use std::slice;
use std::str;
use cassandra::cass_bool_t;
use cassandra::CassValueType_;

use std::str::Utf8Error;

pub unsafe fn raw2utf8(data: *const i8, length: usize) -> Result<String, Utf8Error> {
    let slice = slice::from_raw_parts(data as *const u8, length as usize);
    Ok(try!(str::from_utf8(slice)).to_owned())
}

impl PartialEq for cass_bool_t {
    fn eq(&self, other: &cass_bool_t) -> bool {
        let s: bool = self.clone().into();
        s == other.clone().into()
    }
}

impl PartialEq for CassValueType_ {
    fn eq(&self, other: &CassValueType_) -> bool {
        self == other
    }
}

impl Into<bool> for cass_bool_t {
    fn into(self) -> bool {
        match self {
            cass_bool_t::cass_true => true,
            cass_bool_t::cass_false => false,
        }
    }
}

impl From<bool> for cass_bool_t {
    fn from(b: bool) -> Self {
        if b {
            cass_bool_t::cass_true
        } else {
            cass_bool_t::cass_false
        }
    }
}