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);
}
}