gio/dbus_property_info.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{DBusPropertyInfo, DBusPropertyInfoFlags};
4use glib::translate::*;
5use std::ffi::CStr;
6
7// SAFETY:
8// though not explicitly documented, this struct is assumed to be immutable after creation
9// (with the exception of ref_count of course). See usage in gdbusconnection.c
10
11impl DBusPropertyInfo {
12 pub fn name(&self) -> &str {
13 // SAFETY: See top-level comment.
14 unsafe {
15 let c_obj = self.as_ptr();
16 let name = (*c_obj).name;
17 assert!(!name.is_null());
18 let c_str = CStr::from_ptr(name);
19 c_str.to_str().unwrap()
20 }
21 }
22
23 pub fn signature(&self) -> &str {
24 // SAFETY: See top-level comment.
25 unsafe {
26 let c_obj = self.as_ptr();
27 let signature = (*c_obj).signature;
28 assert!(!signature.is_null());
29 let c_str = CStr::from_ptr(signature);
30 c_str.to_str().unwrap()
31 }
32 }
33
34 pub fn flags(&self) -> DBusPropertyInfoFlags {
35 unsafe {
36 let c_obj = self.as_ptr();
37 let flags = (*c_obj).flags;
38 from_glib(flags)
39 }
40 }
41}