1//! Small wrapper functions over FFI things.
23use std::ffi::{c_char, CStr, CString};
45use crate::ffi;
6use libc::free;
78/// Gets a given value from Minion's TableOut (where it stores run statistics).
9pub fn get_from_table(key: String) -> Option<String> {
10unsafe {
11#[allow(clippy::expect_used)]
12let c_string = CString::new(key).expect("");
13let key_ptr = c_string.into_raw();
14let val_ptr: *mut c_char = ffi::TableOut_get(key_ptr);
1516 drop(CString::from_raw(key_ptr));
1718if val_ptr.is_null() {
19 free(val_ptr as _);
20None
21} else {
22#[allow(clippy::unwrap_used)]
23// CStr borrows the string in the ptr.
24 // We convert it to &str then clone into a String.
25let res = CStr::from_ptr(val_ptr).to_str().unwrap().to_owned();
26 free(val_ptr as _);
27Some(res)
28 }
29 }
30}