13
13
//! [`SCPreferences`]: https://developer.apple.com/documentation/systemconfiguration/scpreferences
14
14
15
15
16
- use core_foundation:: base:: CFAllocatorRef ;
17
- use core_foundation:: base:: TCFType ;
16
+ use core_foundation:: base:: { CFAllocatorRef , TCFType } ;
18
17
use core_foundation:: string:: CFString ;
19
18
20
19
pub use system_configuration_sys:: preferences:: * ;
@@ -31,18 +30,37 @@ impl_TCFType!(SCPreferences, SCPreferencesRef, SCPreferencesGetTypeID);
31
30
32
31
33
32
impl SCPreferences {
34
- /// Initiates access to the per-system set of configuration preferences.
35
- pub fn new ( allocator : CFAllocatorRef , name : & str , prefs_id : Option < & str > ) -> Self {
36
- let prefs_id = match prefs_id {
37
- Some ( prefs_id) => CFString :: new ( prefs_id) . as_concrete_TypeRef ( ) ,
33
+ /// Initiates access to the default system preferences using the default allocator.
34
+ pub fn default ( calling_process_name : & CFString ) -> Self {
35
+ Self :: with_allocator ( ptr:: null ( ) , calling_process_name, None )
36
+ }
37
+
38
+ /// Initiates access to the given (`prefs_id`) group of configuration preferences using the
39
+ /// default allocator. To access the default system preferences, use the [`default`]
40
+ /// constructor.
41
+ ///
42
+ /// [`default`]: #method.default
43
+ pub fn group ( calling_process_name : & CFString , prefs_id : & CFString ) -> Self {
44
+ Self :: with_allocator ( ptr:: null ( ) , calling_process_name, Some ( prefs_id) )
45
+ }
46
+
47
+ /// Initiates access to the per-system set of configuration preferences with a given
48
+ /// allocator and preference group to access.
49
+ pub fn with_allocator (
50
+ allocator : CFAllocatorRef ,
51
+ calling_process_name : & CFString ,
52
+ prefs_id : Option < & CFString > ,
53
+ ) -> Self {
54
+ let prefs_id_ptr = match prefs_id {
55
+ Some ( prefs_id) => prefs_id. as_concrete_TypeRef ( ) ,
38
56
None => ptr:: null ( ) ,
39
57
} ;
40
58
41
59
unsafe {
42
60
SCPreferences :: wrap_under_get_rule ( SCPreferencesCreate (
43
61
allocator,
44
- CFString :: new ( name ) . as_concrete_TypeRef ( ) ,
45
- prefs_id ,
62
+ calling_process_name . as_concrete_TypeRef ( ) ,
63
+ prefs_id_ptr ,
46
64
) )
47
65
}
48
66
}
0 commit comments