Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit 185be95

Browse files
committed
clippy lint fixes
1 parent ae59ad2 commit 185be95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+543
-571
lines changed

src/apm/event.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ impl<'a> Display for CommandResult<'a> {
4646
CommandResult::Success { duration,
4747
ref reply,
4848
ref command_name,
49-
request_id: _,
50-
ref connection_string } => {
49+
ref connection_string,
50+
.. } => {
5151
fmt.write_fmt(format_args!("COMMAND.{} {} COMPLETED: {} ({} ns)",
5252
command_name,
5353
connection_string,
@@ -56,9 +56,9 @@ impl<'a> Display for CommandResult<'a> {
5656
}
5757
CommandResult::Failure { duration,
5858
ref command_name,
59-
ref failure,
60-
request_id: _,
61-
ref connection_string } => {
59+
failure,
60+
ref connection_string,
61+
.. } => {
6262
fmt.write_fmt(format_args!("COMMAND.{} {} FAILURE: {} ({} ns)",
6363
command_name,
6464
connection_string,

src/auth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl Authenticator {
146146

147147
// Compute client key
148148
let mut client_key_hmac = Hmac::new(Sha1::new(), &salted_password[..]);
149-
let client_key_bytes = "Client Key".as_bytes();
149+
let client_key_bytes = b"Client Key";
150150
client_key_hmac.input(client_key_bytes);
151151
let client_key = client_key_hmac.result().code().to_owned();
152152

@@ -209,7 +209,7 @@ impl Authenticator {
209209

210210
// Compute server key
211211
let mut server_key_hmac = Hmac::new(Sha1::new(), &auth_data.salted_password[..]);
212-
let server_key_bytes = "Server Key".as_bytes();
212+
let server_key_bytes = b"Server Key";
213213
server_key_hmac.input(server_key_bytes);
214214
let server_key = server_key_hmac.result().code().to_owned();
215215

src/coll/batch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ impl Batch {
116116
/// Returns `None` on success, or the model that couldn't be merged on
117117
/// failure.
118118
pub fn merge_model(&mut self, model: WriteModel) -> Option<WriteModel> {
119-
match self {
120-
&mut Batch::Insert(ref mut docs) => {
119+
match *self {
120+
Batch::Insert(ref mut docs) => {
121121
match model {
122122
WriteModel::InsertOne { document } => docs.push(document),
123123
_ => return Some(model),
124124
}
125125
}
126-
&mut Batch::Delete(ref mut models) => {
126+
Batch::Delete(ref mut models) => {
127127
match model {
128128
WriteModel::DeleteOne { filter } => {
129129
models.push(DeleteModel {
@@ -140,7 +140,7 @@ impl Batch {
140140
_ => return Some(model),
141141
}
142142
}
143-
&mut Batch::Update(ref mut models) => {
143+
Batch::Update(ref mut models) => {
144144
match model {
145145
WriteModel::ReplaceOne { filter, replacement: update, upsert } => {
146146
models.push(UpdateModel {

src/coll/error.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ impl fmt::Display for BulkWriteException {
100100
try!(write!(fmt, "{:?}\n", v));
101101
}
102102

103-
match self.write_concern_error {
104-
Some(ref error) => try!(write!(fmt, "{:?}\n", error)),
105-
None => (),
103+
if let Some(ref error) = self.write_concern_error {
104+
try!(write!(fmt, "{:?}\n", error));
106105
}
107106

108107
for v in &self.write_errors {
@@ -138,9 +137,8 @@ impl WriteException {
138137
None => "".to_owned(),
139138
};
140139

141-
match w_err {
142-
Some(ref error) => s.push_str(&format!("{:?}\n", error)[..]),
143-
None => (),
140+
if let Some(ref error) = w_err {
141+
s.push_str(&format!("{:?}\n", error)[..]);
144142
}
145143

146144
WriteException {
@@ -155,7 +153,7 @@ impl WriteException {
155153
pub fn with_bulk_exception(bulk_exception: BulkWriteException) -> WriteException {
156154
let len = bulk_exception.write_errors.len();
157155
let write_error = match bulk_exception.write_errors.get(len - 1) {
158-
Some(ref e) => Some(WriteError::new(e.code, e.message.to_owned())),
156+
Some(e) => Some(WriteError::new(e.code, e.message.to_owned())),
159157
None => None,
160158
};
161159

@@ -341,7 +339,7 @@ impl BulkWriteException {
341339

342340
let mut vec = Vec::new();
343341
for err in errors {
344-
if let &Bson::Document(ref doc) = err {
342+
if let Bson::Document(ref doc) = *err {
345343
vec.push(try!(BulkWriteError::parse(doc.clone())));
346344
} else {
347345
return Err(Error::ResponseError("WriteError provided was not a bson \

src/coll/mod.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Collection {
6969
/// Extracts the collection name from the namespace.
7070
/// If the namespace is invalid, this method will panic.
7171
pub fn name(&self) -> String {
72-
match self.namespace.find(".") {
72+
match self.namespace.find('.') {
7373
Some(idx) => {
7474
self.namespace[self.namespace
7575
.char_indices()
@@ -96,7 +96,7 @@ impl Collection {
9696
pipeline: Vec<bson::Document>,
9797
options: Option<AggregateOptions>)
9898
-> Result<Cursor> {
99-
let opts = options.unwrap_or(AggregateOptions::new());
99+
let opts = options.unwrap_or_else(AggregateOptions::new);
100100

101101
let pipeline_map = pipeline.iter()
102102
.map(|bdoc| Bson::Document(bdoc.to_owned()))
@@ -121,7 +121,7 @@ impl Collection {
121121
filter: Option<bson::Document>,
122122
options: Option<CountOptions>)
123123
-> Result<i64> {
124-
let opts = options.unwrap_or(CountOptions::new());
124+
let opts = options.unwrap_or_else(CountOptions::new);
125125

126126
let mut spec = bson::Document::new();
127127
spec.insert("count", Bson::String(self.name()));
@@ -154,7 +154,7 @@ impl Collection {
154154
options: Option<DistinctOptions>)
155155
-> Result<Vec<Bson>> {
156156

157-
let opts = options.unwrap_or(DistinctOptions::new());
157+
let opts = options.unwrap_or_else(DistinctOptions::new);
158158

159159
let mut spec = bson::Document::new();
160160
spec.insert("distinct", Bson::String(self.name()));
@@ -184,20 +184,20 @@ impl Collection {
184184
options: Option<FindOptions>,
185185
cmd_type: CommandType)
186186
-> Result<Cursor> {
187-
let options = options.unwrap_or(FindOptions::new());
187+
let options = options.unwrap_or_else(FindOptions::new);
188188
let flags = OpQueryFlags::with_find_options(&options);
189189

190190
let doc = if options.sort.is_some() {
191191
let mut doc = bson::Document::new();
192192
doc.insert("$query".to_owned(),
193-
Bson::Document(filter.unwrap_or(bson::Document::new())));
193+
Bson::Document(filter.unwrap_or_else(bson::Document::new)));
194194

195195
doc.insert("$orderby".to_owned(),
196196
Bson::Document(options.sort.as_ref().unwrap().clone()));
197197

198198
doc
199199
} else {
200-
filter.unwrap_or(bson::Document::new())
200+
filter.unwrap_or_else(bson::Document::new)
201201
};
202202

203203
let read_pref = options.read_preference.unwrap_or(self.read_preference.to_owned());
@@ -228,7 +228,7 @@ impl Collection {
228228
options: Option<FindOptions>,
229229
cmd_type: CommandType)
230230
-> Result<Option<bson::Document>> {
231-
let options = options.unwrap_or(FindOptions::new());
231+
let options = options.unwrap_or_else(FindOptions::new);
232232
let mut cursor = try!(self.find_with_command_type(filter, Some(options.with_limit(1)),
233233
cmd_type));
234234
match cursor.next() {
@@ -313,7 +313,7 @@ impl Collection {
313313
options: Option<FindOneAndDeleteOptions>)
314314
-> Result<Option<bson::Document>> {
315315

316-
let opts = options.unwrap_or(FindOneAndDeleteOptions::new());
316+
let opts = options.unwrap_or_else(FindOneAndDeleteOptions::new);
317317
let mut cmd = bson::Document::new();
318318
cmd.insert("remove", Bson::Boolean(true));
319319
self.find_and_modify(&mut cmd,
@@ -332,7 +332,7 @@ impl Collection {
332332
replacement: bson::Document,
333333
options: Option<FindOneAndUpdateOptions>)
334334
-> Result<Option<bson::Document>> {
335-
let opts = options.unwrap_or(FindOneAndUpdateOptions::new());
335+
let opts = options.unwrap_or_else(FindOneAndUpdateOptions::new);
336336
try!(Collection::validate_replace(&replacement));
337337
self.find_one_and_replace_or_update(filter,
338338
replacement,
@@ -352,7 +352,7 @@ impl Collection {
352352
update: bson::Document,
353353
options: Option<FindOneAndUpdateOptions>)
354354
-> Result<Option<bson::Document>> {
355-
let opts = options.unwrap_or(FindOneAndUpdateOptions::new());
355+
let opts = options.unwrap_or_else(FindOneAndUpdateOptions::new);
356356
try!(Collection::validate_update(&update));
357357
self.find_one_and_replace_or_update(filter,
358358
update,
@@ -433,9 +433,8 @@ impl Collection {
433433
for model in requests {
434434
let last_index = batches.len() - 1;
435435

436-
match batches[last_index].merge_model(model) {
437-
Some(model) => batches.push(Batch::from(model)),
438-
None => (),
436+
if let Some(model) = batches[last_index].merge_model(model) {
437+
batches.push(Batch::from(model));
439438
}
440439
}
441440

@@ -659,7 +658,7 @@ impl Collection {
659658
docs: Vec<bson::Document>,
660659
options: Option<InsertManyOptions>)
661660
-> Result<InsertManyResult> {
662-
let options = options.unwrap_or(InsertManyOptions::new(false, None));
661+
let options = options.unwrap_or_else(|| InsertManyOptions::new(false, None));
663662
let (ids, exception) = try!(self.insert(docs,
664663
options.ordered,
665664
options.write_concern,
@@ -826,8 +825,8 @@ impl Collection {
826825
replacement: bson::Document,
827826
options: Option<ReplaceOptions>)
828827
-> Result<UpdateResult> {
829-
let options = options.unwrap_or(ReplaceOptions::new(false, None));
830-
let _ = try!(Collection::validate_replace(&replacement));
828+
let options = options.unwrap_or_else(|| ReplaceOptions::new(false, None));
829+
try!(Collection::validate_replace(&replacement));
831830
self.update(filter,
832831
replacement,
833832
options.upsert,
@@ -841,8 +840,8 @@ impl Collection {
841840
update: bson::Document,
842841
options: Option<UpdateOptions>)
843842
-> Result<UpdateResult> {
844-
let options = options.unwrap_or(UpdateOptions::new(false, None));
845-
let _ = try!(Collection::validate_update(&update));
843+
let options = options.unwrap_or_else(|| UpdateOptions::new(false, None));
844+
try!(Collection::validate_update(&update));
846845
self.update(filter, update, options.upsert, false, options.write_concern)
847846
}
848847

@@ -852,14 +851,14 @@ impl Collection {
852851
update: bson::Document,
853852
options: Option<UpdateOptions>)
854853
-> Result<UpdateResult> {
855-
let options = options.unwrap_or(UpdateOptions::new(false, None));
856-
let _ = try!(Collection::validate_update(&update));
854+
let options = options.unwrap_or_else(|| UpdateOptions::new(false, None));
855+
try!(Collection::validate_update(&update));
857856
self.update(filter, update, options.upsert, true, options.write_concern)
858857
}
859858

860859
fn validate_replace(replacement: &bson::Document) -> Result<()> {
861860
for key in replacement.keys() {
862-
if key.starts_with("$") {
861+
if key.starts_with('$') {
863862
return Err(ArgumentError("Replacement cannot include $ operators.".to_owned()));
864863
}
865864
}
@@ -868,7 +867,7 @@ impl Collection {
868867

869868
fn validate_update(update: &bson::Document) -> Result<()> {
870869
for key in update.keys() {
871-
if !key.starts_with("$") {
870+
if !key.starts_with('$') {
872871
return Err(ArgumentError("Update only works with $ operators.".to_owned()));
873872
}
874873
}

src/coll/options.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum WriteModel {
4444
}
4545

4646
/// Options for aggregation queries.
47-
#[derive(Clone)]
47+
#[derive(Clone, Default)]
4848
pub struct AggregateOptions {
4949
pub allow_disk_use: bool,
5050
pub use_cursor: bool,
@@ -54,7 +54,7 @@ pub struct AggregateOptions {
5454
}
5555

5656
/// Options for count queries.
57-
#[derive(Clone)]
57+
#[derive(Clone, Default)]
5858
pub struct CountOptions {
5959
pub skip: u64,
6060
pub limit: i64,
@@ -65,7 +65,7 @@ pub struct CountOptions {
6565
}
6666

6767
/// Options for distinct queries.
68-
#[derive(Clone)]
68+
#[derive(Clone, Default)]
6969
pub struct DistinctOptions {
7070
pub max_time_ms: Option<i64>,
7171
pub read_preference: Option<ReadPreference>,
@@ -89,16 +89,16 @@ pub struct FindOptions {
8989
pub read_preference: Option<ReadPreference>,
9090
}
9191

92-
/// Options for findOneAndDelete operations.
93-
#[derive(Clone)]
92+
/// Options for `findOneAndDelete` operations.
93+
#[derive(Clone, Default)]
9494
pub struct FindOneAndDeleteOptions {
9595
pub max_time_ms: Option<i64>,
9696
pub projection: Option<bson::Document>,
9797
pub sort: Option<bson::Document>,
9898
pub write_concern: Option<WriteConcern>,
9999
}
100100

101-
/// Options for findOneAndUpdate operations.
101+
/// Options for `findOneAndUpdate` operations.
102102
#[derive(Clone)]
103103
pub struct FindOneAndUpdateOptions {
104104
pub return_document: ReturnDocument,
@@ -110,7 +110,7 @@ pub struct FindOneAndUpdateOptions {
110110
}
111111

112112
/// Options for index operations.
113-
#[derive(Clone)]
113+
#[derive(Clone, Default)]
114114
pub struct IndexOptions {
115115
pub background: Option<bool>,
116116
pub expire_after_seconds: Option<i32>,
@@ -142,14 +142,14 @@ pub struct IndexModel {
142142
}
143143

144144
/// Options for insertMany operations.
145-
#[derive(Clone)]
145+
#[derive(Clone, Default)]
146146
pub struct InsertManyOptions {
147147
pub ordered: bool,
148148
pub write_concern: Option<WriteConcern>,
149149
}
150150

151151
/// Options for update operations.
152-
#[derive(Clone)]
152+
#[derive(Clone, Default)]
153153
pub struct UpdateOptions {
154154
pub upsert: bool,
155155
pub write_concern: Option<WriteConcern>,
@@ -191,6 +191,12 @@ impl DistinctOptions {
191191
}
192192
}
193193

194+
impl Default for FindOptions {
195+
fn default() -> Self {
196+
Self::new()
197+
}
198+
}
199+
194200
impl FindOptions {
195201
/// Creates a new FindOptions struct with default parameters.
196202
pub fn new() -> FindOptions {
@@ -230,6 +236,12 @@ impl FindOneAndDeleteOptions {
230236
}
231237
}
232238

239+
impl Default for FindOneAndUpdateOptions {
240+
fn default() -> Self {
241+
Self::new()
242+
}
243+
}
244+
233245
impl FindOneAndUpdateOptions {
234246
pub fn new() -> FindOneAndUpdateOptions {
235247
FindOneAndUpdateOptions {
@@ -270,7 +282,7 @@ impl IndexModel {
270282
pub fn new(keys: bson::Document, options: Option<IndexOptions>) -> IndexModel {
271283
IndexModel {
272284
keys: keys,
273-
options: options.unwrap_or(IndexOptions::new()),
285+
options: options.unwrap_or_else(IndexOptions::new),
274286
}
275287
}
276288

@@ -292,10 +304,10 @@ impl IndexModel {
292304
name.push_str("_");
293305
}
294306

295-
name.push_str(&key);
296-
name.push_str("_");
297-
match bson {
298-
&Bson::I32(ref i) => name.push_str(&format!("{}", i)),
307+
name.push_str(key);
308+
name.push('_');
309+
match *bson {
310+
Bson::I32(ref i) => name.push_str(&format!("{}", i)),
299311
_ => return Err(ArgumentError("Index model keys must map to i32.".to_owned())),
300312
}
301313
}

0 commit comments

Comments
 (0)