7
7
// except according to those terms.
8
8
9
9
use core_foundation:: array:: { CFArray , CFArrayRef } ;
10
- use core_foundation:: base:: TCFType ;
10
+ use core_foundation:: base:: { TCFType , kCFAllocatorDefault } ;
11
11
use core_foundation:: boolean:: CFBoolean ;
12
12
use core_foundation:: dictionary:: CFDictionary ;
13
13
use core_foundation:: propertylist:: { CFPropertyList , CFPropertyListSubClass } ;
14
14
use core_foundation:: runloop:: CFRunLoopSource ;
15
15
use core_foundation:: string:: CFString ;
16
- use core_foundation_sys:: base:: { CFRelease , kCFAllocatorDefault} ;
17
16
18
17
pub use system_configuration_sys:: dynamic_store:: * ;
19
18
@@ -36,11 +35,8 @@ pub struct SCDynamicStoreCallBackContext<T> {
36
35
///
37
36
/// This is the safe callback definition, abstracting over the lower level `SCDynamicStoreCallBack`
38
37
/// from the `system-configuration-sys` crate.
39
- pub type SCDynamicStoreCallBackT < T > = fn (
40
- store : SCDynamicStore ,
41
- changed_keys : CFArray < CFString > ,
42
- info : & mut T ,
43
- ) ;
38
+ pub type SCDynamicStoreCallBackT < T > =
39
+ fn ( store : SCDynamicStore , changed_keys : CFArray < CFString > , info : & mut T ) ;
44
40
45
41
/// Builder for [`SCDynamicStore`] sessions.
46
42
///
@@ -132,17 +128,13 @@ impl<T> SCDynamicStoreBuilder<T> {
132
128
}
133
129
}
134
130
135
- /// Access to the key-value pairs in the dynamic store of a running system.
136
- ///
137
- /// Use the [`SCDynamicStoreBuilder`] to create instances of this.
138
- ///
139
- /// [`SCDynamicStoreBuilder`]: struct.SCDynamicStoreBuilder.html
140
- pub struct SCDynamicStore ( SCDynamicStoreRef ) ;
141
-
142
- impl Drop for SCDynamicStore {
143
- fn drop ( & mut self ) {
144
- unsafe { CFRelease ( self . as_CFTypeRef ( ) ) }
145
- }
131
+ declare_TCFType ! {
132
+ /// Access to the key-value pairs in the dynamic store of a running system.
133
+ ///
134
+ /// Use the [`SCDynamicStoreBuilder`] to create instances of this.
135
+ ///
136
+ /// [`SCDynamicStoreBuilder`]: struct.SCDynamicStoreBuilder.html
137
+ SCDynamicStore , SCDynamicStoreRef
146
138
}
147
139
148
140
impl_TCFType ! ( SCDynamicStore , SCDynamicStoreRef , SCDynamicStoreGetTypeID ) ;
@@ -189,7 +181,7 @@ impl SCDynamicStore {
189
181
190
182
/// If the given key exists in the store, the associated value is returned.
191
183
///
192
- /// Use `CFPropertyList::downcast ` to cast the result into the correct type.
184
+ /// Use `CFPropertyList::downcast_into ` to cast the result into the correct type.
193
185
pub fn get < S : Into < CFString > > ( & self , key : S ) -> Option < CFPropertyList > {
194
186
let cf_key = key. into ( ) ;
195
187
unsafe {
@@ -205,12 +197,8 @@ impl SCDynamicStore {
205
197
206
198
/// Sets the value of the given key. Overwrites existing values.
207
199
/// Returns `true` on success, false on failure.
208
- pub fn set < S : Into < CFString > , R , V : CFPropertyListSubClass < R > > (
209
- & self ,
210
- key : S ,
211
- value : & V ,
212
- ) -> bool {
213
- self . set_raw ( key, & value. to_CFPropertyList ( ) )
200
+ pub fn set < S : Into < CFString > , V : CFPropertyListSubClass > ( & self , key : S , value : V ) -> bool {
201
+ self . set_raw ( key, & value. into_CFPropertyList ( ) )
214
202
}
215
203
216
204
/// Sets the value of the given key. Overwrites existing values.
@@ -264,7 +252,6 @@ impl SCDynamicStore {
264
252
}
265
253
}
266
254
267
-
268
255
/// The raw callback used by the safe `SCDynamicStore` to convert from the `SCDynamicStoreCallBack`
269
256
/// to the `SCDynamicStoreCallBackT`
270
257
unsafe extern "C" fn convert_callback < T > (
0 commit comments