refactor: move helper functions to utils.rs

This commit is contained in:
2026-09-29 15:05:01 +02:00
parent bda1d6e675
commit 2413cd1659
3 changed files with 18 additions and 14 deletions

View File

@@ -1,3 +1,5 @@
use crate::utils::c_str_to_rs_str_and_free;
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
/* Initting
@@ -141,20 +143,6 @@ pub fn get_server_info() -> Option<ServerInfo> {
})
}
unsafe fn c_str_to_rs_str_and_free(c_str: *mut std::os::raw::c_char) -> Option<String> {
if c_str.is_null() {
return None;
}
let normal_string: String = unsafe { std::ffi::CStr::from_ptr(c_str) }
.to_string_lossy()
.to_string();
unsafe { g_free(c_str as *mut std::ffi::c_void) };
Some(normal_string)
}
/* Setters
*
*/

View File

@@ -4,3 +4,4 @@
pub mod functions;
pub mod notification;
mod utils;

15
src/utils.rs Normal file
View File

@@ -0,0 +1,15 @@
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
pub unsafe fn c_str_to_rs_str_and_free(c_str: *mut std::os::raw::c_char) -> Option<String> {
if c_str.is_null() {
return None;
}
let normal_string: String = unsafe { std::ffi::CStr::from_ptr(c_str) }
.to_string_lossy()
.to_string();
unsafe { g_free(c_str as *mut std::ffi::c_void) };
Some(normal_string)
}