13
13
//! [`SCPreferences`]: https://developer.apple.com/documentation/systemconfiguration/scpreferences-ft8
14
14
15
15
16
- use core_foundation:: base:: { CFAllocatorRef , TCFType } ;
16
+ use core_foundation:: base:: { CFAllocator , TCFType } ;
17
17
use core_foundation:: string:: CFString ;
18
18
19
19
pub use system_configuration_sys:: preferences:: * ;
@@ -32,7 +32,7 @@ impl_TCFType!(SCPreferences, SCPreferencesRef, SCPreferencesGetTypeID);
32
32
impl SCPreferences {
33
33
/// Initiates access to the default system preferences using the default allocator.
34
34
pub fn default ( calling_process_name : & CFString ) -> Self {
35
- Self :: with_allocator ( ptr :: null ( ) , calling_process_name, None )
35
+ Self :: new ( None , calling_process_name, None )
36
36
}
37
37
38
38
/// Initiates access to the given (`prefs_id`) group of configuration preferences using the
@@ -41,29 +41,36 @@ impl SCPreferences {
41
41
///
42
42
/// [`default`]: #method.default
43
43
pub fn group ( calling_process_name : & CFString , prefs_id : & CFString ) -> Self {
44
- Self :: with_allocator ( ptr :: null ( ) , calling_process_name, Some ( prefs_id) )
44
+ Self :: new ( None , calling_process_name, Some ( prefs_id) )
45
45
}
46
46
47
47
/// Initiates access to the per-system set of configuration preferences with a given
48
48
/// allocator and preference group to access. See the underlying [SCPreferencesCreate] function
49
- /// documentation for details.
49
+ /// documentation for details. Use the helper constructors [`default`] and [`group`] to easier
50
+ /// create an instance using the default allocator.
50
51
///
51
52
/// [SCPreferencesCreate]: https://developer.apple.com/documentation/systemconfiguration/1516807-scpreferencescreate?language=objc
52
- pub fn with_allocator (
53
- allocator : CFAllocatorRef ,
53
+ /// [`default`]: #method.default
54
+ /// [`group`]: #method.group
55
+ pub fn new (
56
+ allocator : Option < & CFAllocator > ,
54
57
calling_process_name : & CFString ,
55
58
prefs_id : Option < & CFString > ,
56
59
) -> Self {
57
- let prefs_id_ptr = match prefs_id {
60
+ let allocator_ref = match allocator {
61
+ Some ( allocator) => allocator. as_concrete_TypeRef ( ) ,
62
+ None => ptr:: null ( ) ,
63
+ } ;
64
+ let prefs_id_ref = match prefs_id {
58
65
Some ( prefs_id) => prefs_id. as_concrete_TypeRef ( ) ,
59
66
None => ptr:: null ( ) ,
60
67
} ;
61
68
62
69
unsafe {
63
70
SCPreferences :: wrap_under_create_rule ( SCPreferencesCreate (
64
- allocator ,
71
+ allocator_ref ,
65
72
calling_process_name. as_concrete_TypeRef ( ) ,
66
- prefs_id_ptr ,
73
+ prefs_id_ref ,
67
74
) )
68
75
}
69
76
}
0 commit comments