defaults_rs/preferences/
types.rs

1// SPDX-License-Identifier: MIT
2
3use crate::PrefValue;
4
5/// Preferences domain (user or global).
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub enum Domain {
8    /// A user domain, e.g., "com.apple.finder"
9    User(String),
10    /// The global preferences domain / NSGlobalDomain / .GlobalPreferences
11    Global,
12}
13
14impl Domain {
15    /// Returns the CoreFoundation name for a given domain.
16    pub fn get_cf_name(&self) -> String {
17        match &self {
18            Domain::Global => String::from(".GlobalPreferences"),
19            Domain::User(name) => name.clone(),
20        }
21    }
22}
23
24impl std::fmt::Display for Domain {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        match self {
27            Domain::User(s) => write!(f, "{}", s),
28            Domain::Global => write!(f, "NSGlobalDomain"),
29        }
30    }
31}
32
33/// Result of a find operation.
34#[derive(Debug)]
35pub struct FindMatch {
36    pub key: String,
37    pub value: PrefValue,
38}