@@ -45,8 +45,8 @@ impl Collection {
45
45
write_concern : Option < WriteConcern > )
46
46
-> Collection {
47
47
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 ( ) ) ;
50
50
51
51
if create {
52
52
// Attempt to create the collection explicitly, or fail silently.
@@ -97,7 +97,7 @@ impl Collection {
97
97
options : Option < AggregateOptions > )
98
98
-> Result < Cursor > {
99
99
let pipeline_map: Vec < _ > = pipeline. into_iter ( )
100
- . map ( |bdoc| Bson :: Document ( bdoc ) )
100
+ . map ( Bson :: Document )
101
101
. collect ( ) ;
102
102
103
103
let mut spec = doc ! {
@@ -169,7 +169,7 @@ impl Collection {
169
169
}
170
170
171
171
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 ( ) ) ;
173
173
174
174
let result = try!( self . db . command ( spec, CommandType :: Distinct , Some ( read_preference) ) ) ;
175
175
match result. get ( "values" ) {
@@ -261,7 +261,7 @@ impl Collection {
261
261
cmd = merge_options ( cmd, options) ;
262
262
263
263
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 ( ) ) ;
265
265
try!( WriteException :: validate_write_result ( res. clone ( ) , wc) ) ;
266
266
267
267
let doc = match res. get ( "value" ) {
@@ -554,7 +554,7 @@ impl Collection {
554
554
cmd_type : CommandType )
555
555
-> Result < ( Vec < Bson > , Option < BulkWriteException > ) > {
556
556
557
- let wc = write_concern. unwrap_or ( self . write_concern . clone ( ) ) ;
557
+ let wc = write_concern. unwrap_or_else ( || self . write_concern . clone ( ) ) ;
558
558
559
559
let mut converted_docs = Vec :: new ( ) ;
560
560
let mut ids = Vec :: new ( ) ;
@@ -637,14 +637,14 @@ impl Collection {
637
637
docs : Vec < bson:: Document > ,
638
638
options : Option < InsertManyOptions > )
639
639
-> 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 ( ) ) ;
641
641
642
642
let ( ids, exception) =
643
643
try!( self . insert ( docs, options, write_concern, CommandType :: InsertMany ) ) ;
644
644
645
645
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 ( ) ) ;
648
648
}
649
649
650
650
if let Some ( ref exc) = exception {
@@ -664,7 +664,7 @@ impl Collection {
664
664
cmd_type : CommandType )
665
665
-> Result < BulkDeleteResult > {
666
666
667
- let wc = write_concern. unwrap_or ( self . write_concern . clone ( ) ) ;
667
+ let wc = write_concern. unwrap_or_else ( || self . write_concern . clone ( ) ) ;
668
668
669
669
let mut deletes = Vec :: new ( ) ;
670
670
for model in models {
@@ -739,7 +739,7 @@ impl Collection {
739
739
write_concern : Option < WriteConcern > ,
740
740
cmd_type : CommandType )
741
741
-> 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 ( ) ) ;
743
743
744
744
let mut updates = Vec :: new ( ) ;
745
745
for model in models {
0 commit comments