@@ -25,11 +25,12 @@ impl From<&str> for Field {
2525}
2626
2727/// 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 > ,
3031}
3132
32- impl Record {
33+ impl < ' a > Record < ' a > {
3334 /// Creates an empty [`Record`] with capacity for the count of fields specified.
3435 ///
3536 /// Field indices are 1-based.
@@ -213,10 +214,15 @@ impl Record {
213214 /// Some("this is [1] [2]"),
214215 /// vec![Field::IntegerData(1), Field::StringData("example".to_owned())],
215216 /// );
216- /// assert_eq!(record.integer_data(1), 1 );
217+ /// assert_eq!(record.integer_data(1), Some(1) );
217218 /// ```
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+ }
220226 }
221227
222228 /// Sets an integer field in a [`Record`].
@@ -230,14 +236,22 @@ impl Record {
230236 ///
231237 /// let mut record = Record::new(1);
232238 /// record.set_integer_data(1, 42);
233- /// assert_eq!(record.integer_data(1), 42 );
239+ /// assert_eq!(record.integer_data(1), Some(42) );
234240 /// ```
235241 pub fn set_integer_data ( & self , field : u32 , value : i32 ) {
236242 unsafe {
237243 ffi:: MsiRecordSetInteger ( * self . h , field, value) ;
238244 }
239245 }
240246
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+
241255 /// Gets whether a field is null in a [`Record`].
242256 ///
243257 /// Field indices are 1-based.
@@ -255,21 +269,21 @@ impl Record {
255269 }
256270}
257271
258- impl Deref for Record {
272+ impl < ' a > Deref for Record < ' a > {
259273 type Target = MSIHANDLE ;
260274
261275 fn deref ( & self ) -> & Self :: Target {
262276 & * self . h
263277 }
264278}
265279
266- impl From < MSIHANDLE > for Record {
280+ impl < ' a > From < MSIHANDLE > for Record < ' a > {
267281 fn from ( h : MSIHANDLE ) -> Self {
268282 Record { h : h. to_owned ( ) }
269283 }
270284}
271285
272- impl From < & str > for Record {
286+ impl < ' a > From < & str > for Record < ' a > {
273287 fn from ( s : & str ) -> Self {
274288 unsafe {
275289 let h = ffi:: MsiCreateRecord ( 0u32 ) ;
@@ -282,7 +296,7 @@ impl From<&str> for Record {
282296 }
283297}
284298
285- impl From < String > for Record {
299+ impl < ' a > From < String > for Record < ' a > {
286300 fn from ( s : String ) -> Self {
287301 unsafe {
288302 let h = ffi:: MsiCreateRecord ( 0u32 ) ;
@@ -318,5 +332,12 @@ mod tests {
318332
319333 record. set_string_data ( 1 , None ) ;
320334 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 ) ;
321342 }
322343}
0 commit comments