1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use super::glib;
use super::libc;
use std::ffi::CStr;
use std::ops::Deref;
use std::os::raw::c_char;
#[derive(Debug)]
pub struct GLibString {
ptr: *const CStr,
}
impl GLibString {
pub unsafe fn from_chars(chars: *const c_char) -> Option<Self> {
chars.as_ref().map(|c| Self { ptr: CStr::from_ptr(c) })
}
}
impl Deref for GLibString {
type Target = CStr;
fn deref(&self) -> &CStr {
unsafe { &*self.ptr }
}
}
impl Drop for GLibString {
fn drop(&mut self) {
unsafe { glib::g_free(self.ptr as *mut _) }
}
}
unsafe impl Send for GLibString {}
unsafe impl Sync for GLibString {}
#[derive(Debug)]
pub struct LibcString {
ptr: *const CStr,
}
impl LibcString {
pub unsafe fn from_chars(chars: *const c_char) -> Option<Self> {
chars.as_ref().map(|c| Self { ptr: CStr::from_ptr(c) })
}
}
impl Deref for LibcString {
type Target = CStr;
fn deref(&self) -> &CStr {
unsafe { &*self.ptr }
}
}
impl Drop for LibcString {
fn drop(&mut self) {
unsafe { libc::free(self.ptr as *mut _) }
}
}
unsafe impl Send for LibcString {}
unsafe impl Sync for LibcString {}