Skip to main content

Preferences

Struct Preferences 

Source
pub struct Preferences { /* private fields */ }

Implementations§

Source§

impl Preferences

Source

pub fn type_id() -> u64

Source

pub fn new(name: &str, prefs_id: Option<&str>) -> Result<Self>

Examples found in repository?
examples/07_network_sets.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.network-sets-example", None)?;
5    let current = NetworkSet::copy_current(&prefs).and_then(|set| set.name());
6    println!("current_set={current:?}");
7    for set in NetworkSet::copy_all(&prefs) {
8        println!("set_id={:?} name={:?} services={}", set.set_id(), set.name(), set.copy_services().len());
9    }
10    Ok(())
11}
More examples
Hide additional examples
examples/06_network_services.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.network-services-example", None)?;
5    for service in prefs.network_services() {
6        println!(
7            "id={:?} enabled={} name={:?} protocols={}",
8            service.service_id()?,
9            service.is_enabled(),
10            service.name()?,
11            service.copy_protocols().len()
12        );
13    }
14    Ok(())
15}
examples/04_preferences_session.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.preferences-example", None)?;
5    let keys = prefs.copy_key_list();
6    println!("key_count={}", keys.len());
7    if let Some(first_key) = keys.first() {
8        println!("first_key={first_key}");
9        println!("first_value_present={}", prefs.get_value(first_key)?.is_some());
10    }
11    println!("signature_present={}", prefs.signature().is_some());
12    Ok(())
13}
examples/09_network_protocol.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.network-protocol-example", None)?;
5    if let Some(protocol) = NetworkService::copy_all(&prefs)
6        .into_iter()
7        .flat_map(|service| service.copy_protocols())
8        .next()
9    {
10        println!(
11            "protocol_type={:?} enabled={} has_config={}",
12            protocol.protocol_type(),
13            protocol.is_enabled(),
14            protocol.configuration().is_some()
15        );
16    } else {
17        println!("no network protocols available");
18    }
19    Ok(())
20}
Source

pub fn new_with_authorization( name: &str, prefs_id: Option<&str>, ) -> Result<Self>

Source

pub unsafe fn new_with_authorization_raw( name: &str, prefs_id: Option<&str>, authorization: Option<NonNull<c_void>>, ) -> Result<Self>

§Safety

authorization must be a valid AuthorizationRef obtained from a compatible Security-framework binding, and it must remain valid for the lifetime requirements imposed by SCPreferences.

Source

pub fn new_with_callback<F>( name: &str, prefs_id: Option<&str>, callback: F, ) -> Result<Self>
where F: FnMut(PreferencesNotification) + Send + 'static,

Source

pub fn new_with_authorization_and_callback<F>( name: &str, prefs_id: Option<&str>, callback: F, ) -> Result<Self>
where F: FnMut(PreferencesNotification) + Send + 'static,

Source

pub unsafe fn new_with_authorization_raw_and_callback<F>( name: &str, prefs_id: Option<&str>, authorization: Option<NonNull<c_void>>, callback: F, ) -> Result<Self>
where F: FnMut(PreferencesNotification) + Send + 'static,

§Safety

authorization must be a valid AuthorizationRef obtained from a compatible Security-framework binding, and it must remain valid for the lifetime requirements imposed by SCPreferences.

Source

pub fn set_callback<F>(&mut self, callback: F) -> Result<()>
where F: FnMut(PreferencesNotification) + Send + 'static,

Source

pub fn clear_callback(&mut self) -> Result<()>

Source

pub fn schedule_with_run_loop_current(&self) -> Result<()>

Source

pub fn unschedule_from_run_loop_current(&self) -> Result<()>

Source

pub fn set_dispatch_queue_global(&self) -> Result<()>

Source

pub fn clear_dispatch_queue(&self) -> Result<()>

Source

pub fn lock(&self, wait: bool) -> Result<()>

Source

pub fn commit_changes(&self) -> Result<()>

Source

pub fn apply_changes(&self) -> Result<()>

Source

pub fn unlock(&self) -> Result<()>

Source

pub fn synchronize(&self)

Source

pub fn signature(&self) -> Option<String>

Examples found in repository?
examples/04_preferences_session.rs (line 11)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.preferences-example", None)?;
5    let keys = prefs.copy_key_list();
6    println!("key_count={}", keys.len());
7    if let Some(first_key) = keys.first() {
8        println!("first_key={first_key}");
9        println!("first_value_present={}", prefs.get_value(first_key)?.is_some());
10    }
11    println!("signature_present={}", prefs.signature().is_some());
12    Ok(())
13}
Source

pub fn copy_key_list(&self) -> Vec<String>

Examples found in repository?
examples/04_preferences_session.rs (line 5)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.preferences-example", None)?;
5    let keys = prefs.copy_key_list();
6    println!("key_count={}", keys.len());
7    if let Some(first_key) = keys.first() {
8        println!("first_key={first_key}");
9        println!("first_value_present={}", prefs.get_value(first_key)?.is_some());
10    }
11    println!("signature_present={}", prefs.signature().is_some());
12    Ok(())
13}
Source

pub fn get_value(&self, key: &str) -> Result<Option<PropertyList>>

Examples found in repository?
examples/04_preferences_session.rs (line 9)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.preferences-example", None)?;
5    let keys = prefs.copy_key_list();
6    println!("key_count={}", keys.len());
7    if let Some(first_key) = keys.first() {
8        println!("first_key={first_key}");
9        println!("first_value_present={}", prefs.get_value(first_key)?.is_some());
10    }
11    println!("signature_present={}", prefs.signature().is_some());
12    Ok(())
13}
Source

pub fn add_value(&self, key: &str, value: &PropertyList) -> Result<()>

Source

pub fn set_value(&self, key: &str, value: &PropertyList) -> Result<()>

Source

pub fn remove_value(&self, key: &str) -> Result<()>

Source

pub fn path_create_unique_child(&self, prefix: &str) -> Result<Option<String>>

Source

pub fn path_get_value(&self, path: &str) -> Result<Option<PropertyList>>

Source

pub fn path_set_value(&self, path: &str, value: &PropertyList) -> Result<()>

Source

pub fn path_remove_value(&self, path: &str) -> Result<()>

Source

pub fn set_computer_name(&self, name: Option<&str>) -> Result<()>

Source

pub fn set_local_host_name(&self, name: Option<&str>) -> Result<()>

Source

pub fn network_services(&self) -> Vec<NetworkService>

Examples found in repository?
examples/06_network_services.rs (line 5)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.network-services-example", None)?;
5    for service in prefs.network_services() {
6        println!(
7            "id={:?} enabled={} name={:?} protocols={}",
8            service.service_id()?,
9            service.is_enabled(),
10            service.name()?,
11            service.copy_protocols().len()
12        );
13    }
14    Ok(())
15}

Trait Implementations§

Source§

impl Clone for Preferences

Source§

fn clone(&self) -> Preferences

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Preferences

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.