gio/
file_attribute_info.rs
1use std::{fmt, mem, ptr};
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9 #[doc(alias = "GFileAttributeInfo")]
11 pub struct FileAttributeInfo(BoxedInline<ffi::GFileAttributeInfo>);
12
13 match fn {
14 copy => |ptr| {
15 let copy = glib::ffi::g_malloc0(mem::size_of::<ffi::GFileAttributeInfo>()) as *mut ffi::GFileAttributeInfo;
16 (*copy).name = glib::ffi::g_strdup((*ptr).name);
17 copy
18 },
19 free => |ptr| {
20 glib::ffi::g_free((*ptr).name as *mut _);
21 glib::ffi::g_free(ptr as *mut _);
22 },
23 init => |ptr| {
24 *ptr = mem::zeroed();
25 },
26 copy_into => |dest, src| {
27 ptr::copy_nonoverlapping(src, dest, 1);
28 (*dest).name = glib::ffi::g_strdup((*dest).name);
29 },
30 clear => |ptr| {
31 glib::ffi::g_free((*ptr).name as *mut _);
32 },
33 }
34}
35
36impl FileAttributeInfo {
37 #[inline]
38 pub fn name(&self) -> &str {
39 unsafe {
40 use std::ffi::CStr;
41
42 CStr::from_ptr(self.inner.name)
43 .to_str()
44 .expect("non-UTF-8 string")
45 }
46 }
47
48 #[inline]
49 pub fn type_(&self) -> crate::FileAttributeType {
50 unsafe { from_glib(self.inner.type_) }
51 }
52
53 #[inline]
54 pub fn flags(&self) -> crate::FileAttributeInfoFlags {
55 unsafe { from_glib(self.inner.flags) }
56 }
57}
58
59impl fmt::Debug for FileAttributeInfo {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 f.debug_struct("FileAttributeInfo")
62 .field("name", &self.name())
63 .field("type", &self.type_())
64 .field("flags", &self.flags())
65 .finish()
66 }
67}