Skip to content

Commit 55477ed

Browse files
committed
Take higher level CFAllocator instead of CFAllocatorRef
1 parent e78ac6f commit 55477ed

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

system-configuration/src/preferences.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! [`SCPreferences`]: https://developer.apple.com/documentation/systemconfiguration/scpreferences-ft8
1414
1515

16-
use core_foundation::base::{CFAllocatorRef, TCFType};
16+
use core_foundation::base::{CFAllocator, TCFType};
1717
use core_foundation::string::CFString;
1818

1919
pub use system_configuration_sys::preferences::*;
@@ -32,7 +32,7 @@ impl_TCFType!(SCPreferences, SCPreferencesRef, SCPreferencesGetTypeID);
3232
impl SCPreferences {
3333
/// Initiates access to the default system preferences using the default allocator.
3434
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)
3636
}
3737

3838
/// Initiates access to the given (`prefs_id`) group of configuration preferences using the
@@ -41,29 +41,36 @@ impl SCPreferences {
4141
///
4242
/// [`default`]: #method.default
4343
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))
4545
}
4646

4747
/// Initiates access to the per-system set of configuration preferences with a given
4848
/// 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.
5051
///
5152
/// [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>,
5457
calling_process_name: &CFString,
5558
prefs_id: Option<&CFString>,
5659
) -> 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 {
5865
Some(prefs_id) => prefs_id.as_concrete_TypeRef(),
5966
None => ptr::null(),
6067
};
6168

6269
unsafe {
6370
SCPreferences::wrap_under_create_rule(SCPreferencesCreate(
64-
allocator,
71+
allocator_ref,
6572
calling_process_name.as_concrete_TypeRef(),
66-
prefs_id_ptr,
73+
prefs_id_ref,
6774
))
6875
}
6976
}

0 commit comments

Comments
 (0)