From 2413cd1659fdf03c21e864b2fcc84d805041d107 Mon Sep 17 00:00:00 2001 From: szymon Date: Tue, 29 Sep 2026 15:05:01 +0200 Subject: [PATCH] refactor: move helper functions to utils.rs --- src/functions.rs | 16 ++-------------- src/lib.rs | 1 + src/utils.rs | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 src/utils.rs diff --git a/src/functions.rs b/src/functions.rs index 44e4562..848f256 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -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 { }) } -unsafe fn c_str_to_rs_str_and_free(c_str: *mut std::os::raw::c_char) -> Option { - 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 * */ diff --git a/src/lib.rs b/src/lib.rs index 1282707..4283c7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,3 +4,4 @@ pub mod functions; pub mod notification; +mod utils; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..e6c4bb7 --- /dev/null +++ b/src/utils.rs @@ -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 { + 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) +}