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