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