mirror of
https://github.com/szymon-jozef/libnotify-rs.git
synced 2026-10-27 19:20:43 +01:00
refactor: move helper functions to utils.rs
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::utils::c_str_to_rs_str_and_free;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||||
|
|
||||||
/* Initting
|
/* 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
|
/* Setters
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,3 +4,4 @@
|
|||||||
|
|
||||||
pub mod functions;
|
pub mod functions;
|
||||||
pub mod notification;
|
pub mod notification;
|
||||||
|
mod utils;
|
||||||
|
|||||||
15
src/utils.rs
Normal file
15
src/utils.rs
Normal 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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user