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

Commit 4be947c

Browse files
committed
Merge pull request #126 from kyeah/clippy
Formatting with Clippy
2 parents 5c562a3 + 37db9ac commit 4be947c

File tree

19 files changed

+377
-369
lines changed

19 files changed

+377
-369
lines changed

src/apm/event.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ pub enum CommandResult<'a> {
4040

4141
impl<'a> Display for CommandResult<'a> {
4242
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
43-
match self {
44-
&CommandResult::Success { duration, ref reply, ref command_name, request_id: _,
43+
match *self {
44+
CommandResult::Success { duration, ref reply, ref command_name, request_id: _,
4545
ref connection_string } => {
4646
fmt.write_fmt(format_args!("COMMAND.{} {} COMPLETED: {} ({} ns)", command_name,
4747
connection_string, reply,
4848
duration.separated_string()))
4949
},
50-
&CommandResult::Failure { duration, ref command_name, ref failure, request_id: _,
51-
ref connection_string } => {
50+
CommandResult::Failure { duration, ref command_name, ref failure, request_id: _,
51+
ref connection_string } => {
5252
fmt.write_fmt(format_args!("COMMAND.{} {} FAILURE: {} ({} ns)", command_name,
5353
connection_string, failure,
5454
duration.separated_string()))

src/apm/listener.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ use apm::event::{CommandStarted, CommandResult};
66
use Client;
77
use error::{Error, Result};
88

9+
pub type StartHook = fn(Client, &CommandStarted);
10+
pub type CompletionHook = fn(Client, &CommandResult);
11+
912
pub struct Listener {
1013
no_start_hooks: AtomicBool,
1114
no_completion_hooks: AtomicBool,
12-
start_hooks: RwLock<Vec<fn(Client, &CommandStarted)>>,
13-
completion_hooks: RwLock<Vec<fn(Client, &CommandResult)>>,
15+
start_hooks: RwLock<Vec<StartHook>>,
16+
completion_hooks: RwLock<Vec<CompletionHook>>,
1417
}
1518

1619
impl Listener {
@@ -20,7 +23,7 @@ impl Listener {
2023
start_hooks: RwLock::new(vec![]), completion_hooks: RwLock::new(vec![]) }
2124
}
2225

23-
pub fn add_start_hook(&self, hook: fn(Client, &CommandStarted)) -> Result<()> {
26+
pub fn add_start_hook(&self, hook: StartHook) -> Result<()> {
2427
let mut guard = match self.start_hooks.write() {
2528
Ok(guard) => guard,
2629
Err(_) => return Err(Error::PoisonLockError)
@@ -30,7 +33,7 @@ impl Listener {
3033
Ok(guard.deref_mut().push(hook))
3134
}
3235

33-
pub fn add_completion_hook(&self, hook: fn(Client, &CommandResult)) -> Result<()> {
36+
pub fn add_completion_hook(&self, hook: CompletionHook) -> Result<()> {
3437
let mut guard = match self.completion_hooks.write() {
3538
Ok(guard) => guard,
3639
Err(_) => return Err(Error::PoisonLockError)

src/coll/batch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ impl From<WriteModel> for Batch {
7676

7777
impl Batch {
7878
pub fn len(&self) -> i64 {
79-
let length = match self {
80-
&Batch::Insert(ref v) => v.len(),
81-
&Batch::Delete(ref v) => v.len(),
82-
&Batch::Update(ref v) => v.len(),
79+
let length = match *self {
80+
Batch::Insert(ref v) => v.len(),
81+
Batch::Delete(ref v) => v.len(),
82+
Batch::Update(ref v) => v.len(),
8383
};
8484

8585
length as i64

src/coll/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ impl error::Error for BulkWriteException {
7070

7171
impl fmt::Display for WriteException {
7272
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
73-
let ref wc_err = self.write_concern_error;
74-
let ref w_err = self.write_error;
73+
let wc_err = &self.write_concern_error;
74+
let w_err = &self.write_error;
7575

7676
try!(write!(fmt, "WriteException:\n"));
7777
if wc_err.is_some() {
@@ -286,15 +286,15 @@ impl BulkWriteException {
286286
}
287287
};
288288

289-
for req in exception.processed_requests.iter() {
289+
for req in &exception.processed_requests {
290290
self.processed_requests.push(req.clone());
291291
}
292292

293-
for req in exception.unprocessed_requests.iter() {
293+
for req in &exception.unprocessed_requests {
294294
self.unprocessed_requests.push(req.clone());
295295
}
296296

297-
for err in exception.write_errors.iter() {
297+
for err in &exception.write_errors {
298298
self.write_errors.push(err.clone());
299299
}
300300

src/coll/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl Collection {
735735
let mut names = Vec::with_capacity(models.len());
736736
let mut indexes = Vec::with_capacity(models.len());
737737

738-
for model in models.iter() {
738+
for model in models {
739739
names.push(try!(model.name()));
740740
indexes.push(Bson::Document(try!(model.to_bson())));
741741
}
@@ -746,7 +746,7 @@ impl Collection {
746746
let result = try!(self.db.command(cmd, CommandType::CreateIndexes, None));
747747

748748
match result.get("errmsg") {
749-
Some(&Bson::String(ref msg)) => return Err(OperationError(msg.to_owned())),
749+
Some(&Bson::String(ref msg)) => Err(OperationError(msg.to_owned())),
750750
_ => Ok(names),
751751
}
752752
}
@@ -774,7 +774,7 @@ impl Collection {
774774

775775
let result = try!(self.db.command(cmd, CommandType::DropIndexes, None));
776776
match result.get("errmsg") {
777-
Some(&Bson::String(ref msg)) => return Err(OperationError(msg.to_owned())),
777+
Some(&Bson::String(ref msg)) => Err(OperationError(msg.to_owned())),
778778
_ => Ok(()),
779779
}
780780
}

src/coll/options.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ impl InsertManyOptions {
376376

377377
impl ReturnDocument {
378378
pub fn to_bool(&self) -> bool {
379-
match self {
380-
&ReturnDocument::Before => false,
381-
&ReturnDocument::After => true,
379+
match *self {
380+
ReturnDocument::Before => false,
381+
ReturnDocument::After => true,
382382
}
383383
}
384384
}

src/command_type.rs

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,68 +35,68 @@ pub enum CommandType {
3535

3636
impl CommandType {
3737
pub fn to_str(&self) -> &str {
38-
match self {
39-
&CommandType::Aggregate => "aggregate",
40-
&CommandType::Count => "count",
41-
&CommandType::CreateCollection => "create_collection",
42-
&CommandType::CreateIndexes => "create_indexes",
43-
&CommandType::CreateUser => "create_user",
44-
&CommandType::DeleteMany => "delete_many",
45-
&CommandType::DeleteOne => "delete_one",
46-
&CommandType::Distinct => "distinct",
47-
&CommandType::DropAllUsers => "drop_all_users",
48-
&CommandType::DropCollection => "drop_collection",
49-
&CommandType::DropDatabase => "drop_database",
50-
&CommandType::DropIndexes => "drop_indexes",
51-
&CommandType::DropUser => "drop_user",
52-
&CommandType::Find => "find",
53-
&CommandType::FindOneAndDelete => "find_one_and_delete",
54-
&CommandType::FindOneAndReplace => "find_one_and_replace",
55-
&CommandType::FindOneAndUpdate => "find_one_and_update",
56-
&CommandType::GetUser => "get_user",
57-
&CommandType::GetUsers => "get_users",
58-
&CommandType::InsertMany => "insert_many",
59-
&CommandType::InsertOne => "insert_one",
60-
&CommandType::IsMaster => "is_master",
61-
&CommandType::ListCollections => "list_collections",
62-
&CommandType::ListDatabases => "list_databases",
63-
&CommandType::ListIndexes => "list_indexes",
64-
&CommandType::Suppressed => "suppressed",
65-
&CommandType::UpdateMany => "update_many",
66-
&CommandType::UpdateOne => "update_one",
38+
match *self {
39+
CommandType::Aggregate => "aggregate",
40+
CommandType::Count => "count",
41+
CommandType::CreateCollection => "create_collection",
42+
CommandType::CreateIndexes => "create_indexes",
43+
CommandType::CreateUser => "create_user",
44+
CommandType::DeleteMany => "delete_many",
45+
CommandType::DeleteOne => "delete_one",
46+
CommandType::Distinct => "distinct",
47+
CommandType::DropAllUsers => "drop_all_users",
48+
CommandType::DropCollection => "drop_collection",
49+
CommandType::DropDatabase => "drop_database",
50+
CommandType::DropIndexes => "drop_indexes",
51+
CommandType::DropUser => "drop_user",
52+
CommandType::Find => "find",
53+
CommandType::FindOneAndDelete => "find_one_and_delete",
54+
CommandType::FindOneAndReplace => "find_one_and_replace",
55+
CommandType::FindOneAndUpdate => "find_one_and_update",
56+
CommandType::GetUser => "get_user",
57+
CommandType::GetUsers => "get_users",
58+
CommandType::InsertMany => "insert_many",
59+
CommandType::InsertOne => "insert_one",
60+
CommandType::IsMaster => "is_master",
61+
CommandType::ListCollections => "list_collections",
62+
CommandType::ListDatabases => "list_databases",
63+
CommandType::ListIndexes => "list_indexes",
64+
CommandType::Suppressed => "suppressed",
65+
CommandType::UpdateMany => "update_many",
66+
CommandType::UpdateOne => "update_one",
6767
}
6868
}
6969

7070
pub fn is_write_command(&self) -> bool {
71-
match self {
72-
&CommandType::Aggregate => false,
73-
&CommandType::Count => false,
74-
&CommandType::CreateCollection => true,
75-
&CommandType::CreateIndexes => true,
76-
&CommandType::CreateUser => true,
77-
&CommandType::DeleteMany => true,
78-
&CommandType::DeleteOne => true,
79-
&CommandType::Distinct => false,
80-
&CommandType::DropAllUsers => true,
81-
&CommandType::DropCollection => true,
82-
&CommandType::DropDatabase => true,
83-
&CommandType::DropIndexes => true,
84-
&CommandType::DropUser => true,
85-
&CommandType::Find => false,
86-
&CommandType::FindOneAndDelete => true,
87-
&CommandType::FindOneAndReplace => true,
88-
&CommandType::FindOneAndUpdate => true,
89-
&CommandType::GetUser => false,
90-
&CommandType::GetUsers => false,
91-
&CommandType::InsertMany => true,
92-
&CommandType::InsertOne => true,
93-
&CommandType::IsMaster => false,
94-
&CommandType::ListCollections => false,
95-
&CommandType::ListDatabases => false,
96-
&CommandType::ListIndexes => false,
97-
&CommandType::Suppressed => false,
98-
&CommandType::UpdateMany => true,
99-
&CommandType::UpdateOne => true,
71+
match *self {
72+
CommandType::Aggregate => false,
73+
CommandType::Count => false,
74+
CommandType::CreateCollection => true,
75+
CommandType::CreateIndexes => true,
76+
CommandType::CreateUser => true,
77+
CommandType::DeleteMany => true,
78+
CommandType::DeleteOne => true,
79+
CommandType::Distinct => false,
80+
CommandType::DropAllUsers => true,
81+
CommandType::DropCollection => true,
82+
CommandType::DropDatabase => true,
83+
CommandType::DropIndexes => true,
84+
CommandType::DropUser => true,
85+
CommandType::Find => false,
86+
CommandType::FindOneAndDelete => true,
87+
CommandType::FindOneAndReplace => true,
88+
CommandType::FindOneAndUpdate => true,
89+
CommandType::GetUser => false,
90+
CommandType::GetUsers => false,
91+
CommandType::InsertMany => true,
92+
CommandType::InsertOne => true,
93+
CommandType::IsMaster => false,
94+
CommandType::ListCollections => false,
95+
CommandType::ListDatabases => false,
96+
CommandType::ListIndexes => false,
97+
CommandType::Suppressed => false,
98+
CommandType::UpdateMany => true,
99+
CommandType::UpdateOne => true,
100100
}
101101
}
102102
}

src/connstring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Host {
3737
}
3838

3939
pub fn has_ipc(&self) -> bool {
40-
self.ipc.len() > 0
40+
!self.ipc.is_empty()
4141
}
4242
}
4343

src/cursor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl Cursor {
148148
return Err(Error::CursorNotFoundError);
149149
}
150150

151-
let ref doc = v[0];
151+
let doc = &v[0];
152152

153153
// Extract cursor information
154154
if let Some(&Bson::Document(ref cursor)) = doc.get("cursor") {

src/db/roles.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ pub enum SingleDatabaseRole {
1919

2020
impl ToString for SingleDatabaseRole {
2121
fn to_string(&self) -> String {
22-
let string = match self {
23-
&SingleDatabaseRole::Read => "read",
24-
&SingleDatabaseRole::ReadWrite => "readWrite",
25-
&SingleDatabaseRole::DbAdmin => "dbAdmin",
26-
&SingleDatabaseRole::DbOwner => "dbOwner",
27-
&SingleDatabaseRole::UserAdmin => "userAdmin",
28-
&SingleDatabaseRole::ClusterAdmin => "clusterAdmin",
29-
&SingleDatabaseRole::ClusterManager => "clusterManager",
30-
&SingleDatabaseRole::ClusterMonitor => "clusterMonitor",
31-
&SingleDatabaseRole::HostManager => "hostManager",
32-
&SingleDatabaseRole::Backup => "backup",
33-
&SingleDatabaseRole::Restore => "restore",
22+
let string = match *self {
23+
SingleDatabaseRole::Read => "read",
24+
SingleDatabaseRole::ReadWrite => "readWrite",
25+
SingleDatabaseRole::DbAdmin => "dbAdmin",
26+
SingleDatabaseRole::DbOwner => "dbOwner",
27+
SingleDatabaseRole::UserAdmin => "userAdmin",
28+
SingleDatabaseRole::ClusterAdmin => "clusterAdmin",
29+
SingleDatabaseRole::ClusterManager => "clusterManager",
30+
SingleDatabaseRole::ClusterMonitor => "clusterMonitor",
31+
SingleDatabaseRole::HostManager => "hostManager",
32+
SingleDatabaseRole::Backup => "backup",
33+
SingleDatabaseRole::Restore => "restore",
3434
};
3535

3636
string.to_owned()
@@ -46,11 +46,11 @@ pub enum AllDatabaseRole {
4646

4747
impl ToString for AllDatabaseRole {
4848
fn to_string(&self) -> String {
49-
let string = match self {
50-
&AllDatabaseRole::Read => "read",
51-
&AllDatabaseRole::ReadWrite => "readWrite",
52-
&AllDatabaseRole::UserAdmin => "userAdmin",
53-
&AllDatabaseRole::DbAdmin => "dbAdmin",
49+
let string = match *self {
50+
AllDatabaseRole::Read => "read",
51+
AllDatabaseRole::ReadWrite => "readWrite",
52+
AllDatabaseRole::UserAdmin => "userAdmin",
53+
AllDatabaseRole::DbAdmin => "dbAdmin",
5454
};
5555

5656
string.to_owned()
@@ -67,9 +67,9 @@ pub enum Role {
6767

6868
impl Role {
6969
fn to_bson(&self) -> Bson {
70-
match self {
71-
&Role::All(ref role) => Bson::String(role.to_string()),
72-
&Role::Single { ref role, ref db } => Bson::Document(doc! {
70+
match *self {
71+
Role::All(ref role) => Bson::String(role.to_string()),
72+
Role::Single { ref role, ref db } => Bson::Document(doc! {
7373
"role" => (Bson::String(role.to_string())),
7474
"db" => (Bson::String(db.to_owned()))
7575
})

0 commit comments

Comments
 (0)