@@ -45,8 +45,8 @@ impl Collection {
4545 write_concern : Option < WriteConcern > )
4646 -> Collection {
4747
48- let rp = read_preference. unwrap_or ( db. read_preference . to_owned ( ) ) ;
49- let wc = write_concern. unwrap_or ( db. write_concern . to_owned ( ) ) ;
48+ let rp = read_preference. unwrap_or_else ( || db. read_preference . to_owned ( ) ) ;
49+ let wc = write_concern. unwrap_or_else ( || db. write_concern . to_owned ( ) ) ;
5050
5151 if create {
5252 // Attempt to create the collection explicitly, or fail silently.
@@ -97,7 +97,7 @@ impl Collection {
9797 options : Option < AggregateOptions > )
9898 -> Result < Cursor > {
9999 let pipeline_map: Vec < _ > = pipeline. into_iter ( )
100- . map ( |bdoc| Bson :: Document ( bdoc ) )
100+ . map ( Bson :: Document )
101101 . collect ( ) ;
102102
103103 let mut spec = doc ! {
@@ -169,7 +169,7 @@ impl Collection {
169169 }
170170
171171 let read_preference = options. and_then ( |o| o. read_preference )
172- . unwrap_or ( self . read_preference . clone ( ) ) ;
172+ . unwrap_or_else ( || self . read_preference . clone ( ) ) ;
173173
174174 let result = try!( self . db . command ( spec, CommandType :: Distinct , Some ( read_preference) ) ) ;
175175 match result. get ( "values" ) {
@@ -261,7 +261,7 @@ impl Collection {
261261 cmd = merge_options ( cmd, options) ;
262262
263263 let res = try!( self . db . command ( cmd, cmd_type, None ) ) ;
264- let wc = write_concern. unwrap_or ( self . write_concern . clone ( ) ) ;
264+ let wc = write_concern. unwrap_or_else ( || self . write_concern . clone ( ) ) ;
265265 try!( WriteException :: validate_write_result ( res. clone ( ) , wc) ) ;
266266
267267 let doc = match res. get ( "value" ) {
@@ -554,7 +554,7 @@ impl Collection {
554554 cmd_type : CommandType )
555555 -> Result < ( Vec < Bson > , Option < BulkWriteException > ) > {
556556
557- let wc = write_concern. unwrap_or ( self . write_concern . clone ( ) ) ;
557+ let wc = write_concern. unwrap_or_else ( || self . write_concern . clone ( ) ) ;
558558
559559 let mut converted_docs = Vec :: new ( ) ;
560560 let mut ids = Vec :: new ( ) ;
@@ -637,14 +637,14 @@ impl Collection {
637637 docs : Vec < bson:: Document > ,
638638 options : Option < InsertManyOptions > )
639639 -> Result < InsertManyResult > {
640- let write_concern = options. as_ref ( ) . map ( |opts| opts. write_concern . clone ( ) ) . unwrap_or ( None ) ;
640+ let write_concern = options. as_ref ( ) . map_or ( None , |opts| opts. write_concern . clone ( ) ) ;
641641
642642 let ( ids, exception) =
643643 try!( self . insert ( docs, options, write_concern, CommandType :: InsertMany ) ) ;
644644
645645 let mut map = BTreeMap :: new ( ) ;
646- for i in 0 .. ids. len ( ) {
647- map. insert ( i as i64 , ids . get ( i ) . unwrap ( ) . to_owned ( ) ) ;
646+ for ( i , item ) in ids. iter ( ) . enumerate ( ) {
647+ map. insert ( i as i64 , item . to_owned ( ) ) ;
648648 }
649649
650650 if let Some ( ref exc) = exception {
@@ -664,7 +664,7 @@ impl Collection {
664664 cmd_type : CommandType )
665665 -> Result < BulkDeleteResult > {
666666
667- let wc = write_concern. unwrap_or ( self . write_concern . clone ( ) ) ;
667+ let wc = write_concern. unwrap_or_else ( || self . write_concern . clone ( ) ) ;
668668
669669 let mut deletes = Vec :: new ( ) ;
670670 for model in models {
@@ -739,7 +739,7 @@ impl Collection {
739739 write_concern : Option < WriteConcern > ,
740740 cmd_type : CommandType )
741741 -> Result < BulkUpdateResult > {
742- let wc = write_concern. unwrap_or ( self . write_concern . clone ( ) ) ;
742+ let wc = write_concern. unwrap_or_else ( || self . write_concern . clone ( ) ) ;
743743
744744 let mut updates = Vec :: new ( ) ;
745745 for model in models {
0 commit comments