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
use crate::{resources_register, Resource};
use glib::translate::*;
use std::mem;
use std::ptr;
impl Resource {
#[doc(alias = "g_resource_new_from_data")]
pub fn from_data(data: &glib::Bytes) -> Result<Resource, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let mut data = data.clone();
let data_ptr = glib::ffi::g_bytes_get_data(data.to_glib_none().0, ptr::null_mut());
if data_ptr as usize % mem::align_of::<*const u8>() != 0 {
data = glib::Bytes::from(&*data);
}
let ret = ffi::g_resource_new_from_data(data.to_glib_none().0, &mut error);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
}
#[doc(hidden)]
pub fn resources_register_include_impl(bytes: &'static [u8]) -> Result<(), glib::Error> {
let bytes = glib::Bytes::from_static(bytes);
let resource = Resource::from_data(&bytes)?;
resources_register(&resource);
Ok(())
}
#[macro_export]
macro_rules! resources_register_include {
($path:expr) => {
$crate::resources_register_include_impl(include_bytes!(concat!(
env!("OUT_DIR"),
"/",
$path
)))
};
}