use std::ffi::{c_char, CStr};
use crate::core::{Key, Value};
#[unsafe(no_mangle)]
pub extern "C" fn key_free(val: *mut Key) {
if !val.is_null() {
unsafe { let _ = Box::from_raw(val); }
}
}
#[unsafe(no_mangle)]
pub extern "C" fn key_new(c_name: *const c_char, val: *mut Value) -> *mut Key {
if c_name.is_null() || val.is_null() {
return std::ptr::null_mut()
}
let name = unsafe { CStr::from_ptr(c_name) };
let name = match name.to_str() {
Ok(s) => s,
Err(_) => return std::ptr::null_mut(),
};
unsafe {
let value: Box<Value> = Box::from_raw(val);
Box::into_raw(Box::new(Key::new(name.to_string(), *value)))
}
}