8
8
9
9
use core_foundation:: base:: TCFType ;
10
10
use core_foundation:: boolean:: CFBoolean ;
11
- use core_foundation:: dictionary:: { CFDictionary , CFDictionaryRef } ;
11
+ use core_foundation:: dictionary:: CFDictionary ;
12
+ use core_foundation:: propertylist:: { CFPropertyList , CFPropertyListSubClass } ;
12
13
use core_foundation:: string:: CFString ;
13
14
use core_foundation_sys:: base:: { CFRelease , kCFAllocatorDefault} ;
14
- use core_foundation_sys:: propertylist:: CFPropertyListRef ;
15
15
16
16
use system_configuration_sys:: dynamic_store:: * ;
17
17
@@ -70,15 +70,15 @@ impl SCDynamicStore {
70
70
}
71
71
72
72
/// If the given key exists in the store, the associated value is returned.
73
- pub fn get < S : Into < CFString > > ( & self , key : S ) -> Option < CFDictionary > {
73
+ ///
74
+ /// Use `CFPropertyList::downcast` to cast the result into the correct type.
75
+ pub fn get < S : Into < CFString > > ( & self , key : S ) -> Option < CFPropertyList > {
74
76
let cf_key = key. into ( ) ;
75
77
unsafe {
76
78
let dict_ref =
77
79
SCDynamicStoreCopyValue ( self . as_concrete_TypeRef ( ) , cf_key. as_concrete_TypeRef ( ) ) ;
78
80
if dict_ref != ptr:: null ( ) {
79
- Some ( CFDictionary :: wrap_under_create_rule (
80
- dict_ref as * const _ as CFDictionaryRef ,
81
- ) )
81
+ Some ( CFPropertyList :: wrap_under_create_rule ( dict_ref) )
82
82
} else {
83
83
None
84
84
}
@@ -87,13 +87,23 @@ impl SCDynamicStore {
87
87
88
88
/// Sets the value of the given key. Overwrites existing values.
89
89
/// Returns `true` on success, false on failure.
90
- pub fn set < S : Into < CFString > > ( & self , key : S , value : & CFDictionary ) -> bool {
90
+ pub fn set < S : Into < CFString > , R , V : CFPropertyListSubClass < R > > (
91
+ & self ,
92
+ key : S ,
93
+ value : & V ,
94
+ ) -> bool {
95
+ self . set_raw ( key, & value. to_CFPropertyList ( ) )
96
+ }
97
+
98
+ /// Sets the value of the given key. Overwrites existing values.
99
+ /// Returns `true` on success, false on failure.
100
+ pub fn set_raw < S : Into < CFString > > ( & self , key : S , value : & CFPropertyList ) -> bool {
91
101
let cf_key = key. into ( ) ;
92
102
let success = unsafe {
93
103
SCDynamicStoreSetValue (
94
104
self . as_concrete_TypeRef ( ) ,
95
105
cf_key. as_concrete_TypeRef ( ) ,
96
- value. as_concrete_TypeRef ( ) as CFPropertyListRef ,
106
+ value. as_concrete_TypeRef ( ) ,
97
107
)
98
108
} ;
99
109
success != 0
0 commit comments