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
use libc::c_void;

use crate::util::{util::ref_free_drop, go_type::FFIError};

use self::ffi::nosqldb_get_result_value_as_json;
use self::ffi::nosqldb_get_result_row_exists;


pub(crate) mod ffi {
    use crate::util::{go_type::{NosqldbGetResultPtr, FFIError}, util::{ffi::{FfiBoolAndErrorNewReturn, FfiStringAndErrorNewReturn}, c_char_to_str}};

    use super::NosqldbGetResult;

    extern "C" {
        fn ffi_nosqldb_get_result_row_exists(gtrs: NosqldbGetResultPtr) -> FfiBoolAndErrorNewReturn ;
    }

    pub(crate) fn nosqldb_get_result_row_exists(
        gtrs: &mut NosqldbGetResult
    ) -> Result<bool, FFIError> {
        let FfiBoolAndErrorNewReturn {b: value, go_error_ptr} = unsafe { ffi_nosqldb_get_result_row_exists(gtrs.nosqldb_get_result_ptr) };
        if go_error_ptr.is_null() {
            Ok(value)
        } else {
            Err(FFIError::GoError(c_char_to_str(go_error_ptr)?))
        }
    }

    extern "C" {
        fn ffi_nosqldb_get_result_value_as_json(gtrs: NosqldbGetResultPtr) -> FfiStringAndErrorNewReturn ;
    }

    pub(crate) fn nosqldb_get_result_value_as_json(
        gtrs: &mut NosqldbGetResult
    ) -> Result<String, FFIError> {
        let FfiStringAndErrorNewReturn {c: value, go_error_ptr} = unsafe { ffi_nosqldb_get_result_value_as_json(gtrs.nosqldb_get_result_ptr) };
        if go_error_ptr.is_null() {
            Ok(c_char_to_str(value)?)
        } else {
            Err(FFIError::GoError(c_char_to_str(go_error_ptr)?))
        }
    }
}

#[derive(Debug)]
pub struct NosqldbGetResult {
    pub(crate) nosqldb_get_result_ptr: *const c_void,
}

impl NosqldbGetResult {
    pub fn value_as_json (&mut self) -> Result<String, FFIError> {
        nosqldb_get_result_value_as_json(self)
    }
    pub fn row_exists (&mut self) -> Result<bool, FFIError> {
    nosqldb_get_result_row_exists(self)
    }
}

impl Drop for NosqldbGetResult {
    fn drop(&mut self) {
        ref_free_drop(self.nosqldb_get_result_ptr);
    }
}