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
use types::{gboolean, gpointer, FALSE};
use glib;
use std::ascii;
use std::ascii::AsciiExt;
use std::borrow::Cow;
use std::mem;
use std::str;
#[inline]
pub fn is_true(v: gboolean) -> bool { v != FALSE }
#[inline]
pub fn is_false(v: gboolean) -> bool { v == FALSE }
pub fn escape_bytestring<'a>(s: &'a [u8]) -> Cow<'a, str> {
if s.is_ascii() {
let s = unsafe { str::from_utf8_unchecked(s) };
return s.into();
}
let mut acc = Vec::with_capacity(s.len());
acc.extend(s.iter().cloned().flat_map(ascii::escape_default));
let string = unsafe { String::from_utf8_unchecked(acc) };
string.into()
}
pub unsafe extern "C" fn box_free<T>(raw: gpointer) {
let b: Box<T> = mem::transmute(raw);
mem::drop(b);
}
pub unsafe fn into_destroy_notify(func: unsafe extern "C" fn(gpointer))
-> glib::GDestroyNotify
{
mem::transmute(func)
}
pub unsafe fn box_from_pointer<T>(p: gpointer) -> Box<T> {
mem::transmute(p)
}
pub fn box_into_pointer<T>(b: Box<T>) -> gpointer {
unsafe { mem::transmute(b) }
}