systemconfiguration/
property_list.rs1use crate::{bridge, error::Result, ffi, SystemConfigurationError};
2
3#[derive(Clone, Debug)]
4pub struct PropertyList {
6 raw: bridge::OwnedHandle,
7}
8
9impl PropertyList {
10 pub fn from_string(value: &str) -> Result<Self> {
12 let value = bridge::cstring(value, "sc_property_list_from_string")?;
13 let raw = unsafe { ffi::core::sc_property_list_from_string(value.as_ptr()) };
14 let raw = bridge::owned_handle_or_last("sc_property_list_from_string", raw)?;
15 Ok(Self { raw })
16 }
17
18 pub fn from_bool(value: bool) -> Self {
20 let raw = unsafe { ffi::core::sc_property_list_from_bool(u8::from(value)) };
21 let raw = bridge::owned_handle_or_last("sc_property_list_from_bool", raw)
22 .expect("sc_property_list_from_bool returned null");
23 Self { raw }
24 }
25
26 pub fn from_json(value: &str) -> Result<Self> {
28 let value = bridge::cstring(value, "sc_property_list_from_json")?;
29 let raw = unsafe { ffi::core::sc_property_list_from_json(value.as_ptr()) };
30 let raw = bridge::owned_handle_or_last("sc_property_list_from_json", raw)?;
31 Ok(Self { raw })
32 }
33
34 pub fn description(&self) -> Result<String> {
36 let raw = unsafe { ffi::core::sc_property_list_copy_description(self.raw.as_ptr()) };
37 bridge::take_optional_string(raw).ok_or_else(|| {
38 SystemConfigurationError::null(
39 "sc_property_list_copy_description",
40 "bridge returned null property-list description",
41 )
42 })
43 }
44
45 pub(crate) fn as_ptr(&self) -> bridge::RawHandle {
46 self.raw.as_ptr()
47 }
48
49 pub(crate) fn from_owned_handle(raw: bridge::OwnedHandle) -> Self {
50 Self { raw }
51 }
52}