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
use crate::cassandra::data_type::ConstDataType;
use crate::cassandra::error::*;
use crate::cassandra::iterator::FieldIterator;
use crate::cassandra::util::{Protected, ProtectedInner};
use crate::cassandra::value::Value;
use crate::cassandra_sys::cass_function_meta_argument;
use crate::cassandra_sys::cass_function_meta_argument_count;
use crate::cassandra_sys::cass_function_meta_argument_type_by_name_n;
use crate::cassandra_sys::cass_function_meta_body;
use crate::cassandra_sys::cass_function_meta_called_on_null_input;
use crate::cassandra_sys::cass_function_meta_field_by_name_n;
use crate::cassandra_sys::cass_function_meta_full_name;
use crate::cassandra_sys::cass_function_meta_language;
use crate::cassandra_sys::cass_function_meta_name;
use crate::cassandra_sys::cass_function_meta_return_type;
use crate::cassandra_sys::cass_iterator_fields_from_function_meta;
use crate::cassandra_sys::cass_true;
use crate::cassandra_sys::CassFunctionMeta as _CassFunctionMeta;
use crate::cassandra_sys::CASS_OK;
use std::os::raw::c_char;
use std::{mem, slice, str};
#[derive(Debug)]
pub struct FunctionMeta(*const _CassFunctionMeta);
impl ProtectedInner<*const _CassFunctionMeta> for FunctionMeta {
fn inner(&self) -> *const _CassFunctionMeta {
self.0
}
}
impl Protected<*const _CassFunctionMeta> for FunctionMeta {
fn build(inner: *const _CassFunctionMeta) -> Self {
if inner.is_null() {
panic!("Unexpected null pointer")
};
FunctionMeta(inner)
}
}
impl FunctionMeta {
pub fn fields_iter(&self) -> FieldIterator {
unsafe { FieldIterator::build(cass_iterator_fields_from_function_meta(self.0)) }
}
pub fn get_name(&self) -> String {
let mut name = std::ptr::null();
let mut name_length = 0;
unsafe {
cass_function_meta_name(self.0, &mut name, &mut name_length);
str::from_utf8(slice::from_raw_parts(name as *const u8, name_length))
.expect("must be utf8")
.to_owned()
}
}
pub fn full_name(&self) -> String {
let mut name = std::ptr::null();
let mut name_length = 0;
unsafe {
cass_function_meta_full_name(self.0, &mut name, &mut name_length);
str::from_utf8(slice::from_raw_parts(name as *const u8, name_length))
.expect("must be utf8")
.to_owned()
}
}
pub fn body(&self) -> String {
let mut name = std::ptr::null();
let mut name_length = 0;
unsafe {
cass_function_meta_body(self.0, &mut name, &mut name_length);
str::from_utf8(slice::from_raw_parts(name as *const u8, name_length))
.expect("must be utf8")
.to_owned()
}
}
pub fn language(&self) -> String {
let mut name = std::ptr::null();
let mut name_length = 0;
unsafe {
cass_function_meta_language(self.0, &mut name, &mut name_length);
str::from_utf8(slice::from_raw_parts(name as *const u8, name_length))
.expect("must be utf8")
.to_owned()
}
}
pub fn called_on_null_input(&self) -> bool {
unsafe { cass_function_meta_called_on_null_input(self.0) == cass_true }
}
pub fn argument_count(&self) -> usize {
unsafe { cass_function_meta_argument_count(self.0) }
}
pub fn argument(&self, index: usize) -> Result<()> {
let mut name = std::ptr::null();
let mut name_length = 0;
let mut data_type = std::ptr::null();
unsafe {
cass_function_meta_argument(self.0, index, &mut name, &mut name_length, &mut data_type)
.to_result(())
}
}
pub fn argument_type_by_name(&self, name: &str) -> ConstDataType {
unsafe {
let name_ptr = name.as_ptr() as *const c_char;
ConstDataType::build(cass_function_meta_argument_type_by_name_n(
self.0,
name_ptr,
name.len(),
))
}
}
pub fn return_type(&self) -> ConstDataType {
unsafe { ConstDataType::build(cass_function_meta_return_type(self.0)) }
}
pub fn field_by_name(&self, name: &str) -> Value {
unsafe {
let name_ptr = name.as_ptr() as *const c_char;
Value::build(cass_function_meta_field_by_name_n(
self.0,
name_ptr,
name.len(),
))
}
}
}