@@ -25,11 +25,12 @@ impl From<&str> for Field {
25
25
}
26
26
27
27
/// A collection of [`Field`] containing strings, integers, and byte streams.
28
- pub struct Record {
29
- h : PMSIHANDLE ,
28
+ #[ derive( Clone ) ]
29
+ pub struct Record < ' a > {
30
+ h : PMSIHANDLE < ' a > ,
30
31
}
31
32
32
- impl Record {
33
+ impl < ' a > Record < ' a > {
33
34
/// Creates an empty [`Record`] with capacity for the count of fields specified.
34
35
///
35
36
/// Field indices are 1-based.
@@ -213,10 +214,15 @@ impl Record {
213
214
/// Some("this is [1] [2]"),
214
215
/// vec![Field::IntegerData(1), Field::StringData("example".to_owned())],
215
216
/// );
216
- /// assert_eq!(record.integer_data(1), 1 );
217
+ /// assert_eq!(record.integer_data(1), Some(1) );
217
218
/// ```
218
- pub fn integer_data ( & self , field : u32 ) -> i32 {
219
- unsafe { ffi:: MsiRecordGetInteger ( * self . h , field) }
219
+ pub fn integer_data ( & self , field : u32 ) -> Option < i32 > {
220
+ unsafe {
221
+ match ffi:: MsiRecordGetInteger ( * self . h , field) {
222
+ i if i == ffi:: MSI_NULL_INTEGER => None ,
223
+ i => Some ( i) ,
224
+ }
225
+ }
220
226
}
221
227
222
228
/// Sets an integer field in a [`Record`].
@@ -230,14 +236,22 @@ impl Record {
230
236
///
231
237
/// let mut record = Record::new(1);
232
238
/// record.set_integer_data(1, 42);
233
- /// assert_eq!(record.integer_data(1), 42 );
239
+ /// assert_eq!(record.integer_data(1), Some(42) );
234
240
/// ```
235
241
pub fn set_integer_data ( & self , field : u32 , value : i32 ) {
236
242
unsafe {
237
243
ffi:: MsiRecordSetInteger ( * self . h , field, value) ;
238
244
}
239
245
}
240
246
247
+ /// Reads bytes from a record field that contains stream data.
248
+ ///
249
+ /// Field indices are 1-based.
250
+ #[ allow( unused_variables) ]
251
+ pub fn stream_data ( & self , field : u32 ) -> Vec < u8 > {
252
+ todo ! ( )
253
+ }
254
+
241
255
/// Gets whether a field is null in a [`Record`].
242
256
///
243
257
/// Field indices are 1-based.
@@ -255,21 +269,21 @@ impl Record {
255
269
}
256
270
}
257
271
258
- impl Deref for Record {
272
+ impl < ' a > Deref for Record < ' a > {
259
273
type Target = MSIHANDLE ;
260
274
261
275
fn deref ( & self ) -> & Self :: Target {
262
276
& * self . h
263
277
}
264
278
}
265
279
266
- impl From < MSIHANDLE > for Record {
280
+ impl < ' a > From < MSIHANDLE > for Record < ' a > {
267
281
fn from ( h : MSIHANDLE ) -> Self {
268
282
Record { h : h. to_owned ( ) }
269
283
}
270
284
}
271
285
272
- impl From < & str > for Record {
286
+ impl < ' a > From < & str > for Record < ' a > {
273
287
fn from ( s : & str ) -> Self {
274
288
unsafe {
275
289
let h = ffi:: MsiCreateRecord ( 0u32 ) ;
@@ -282,7 +296,7 @@ impl From<&str> for Record {
282
296
}
283
297
}
284
298
285
- impl From < String > for Record {
299
+ impl < ' a > From < String > for Record < ' a > {
286
300
fn from ( s : String ) -> Self {
287
301
unsafe {
288
302
let h = ffi:: MsiCreateRecord ( 0u32 ) ;
@@ -318,5 +332,12 @@ mod tests {
318
332
319
333
record. set_string_data ( 1 , None ) ;
320
334
assert ! ( record. is_null( 1 ) ) ;
335
+ assert_eq ! ( record. string_data( 1 ) , "" ) ;
336
+ }
337
+
338
+ #[ test]
339
+ fn integer_data_from_string ( ) {
340
+ let record = Record :: with_fields ( None , vec ! [ Field :: StringData ( "test" . to_owned( ) ) ] ) ;
341
+ assert_eq ! ( record. integer_data( 1 ) , None ) ;
321
342
}
322
343
}
0 commit comments