Skip to content

Commit 57beb1f

Browse files
minor: fix clippy
1 parent 9ba94c2 commit 57beb1f

File tree

7 files changed

+57
-36
lines changed

7 files changed

+57
-36
lines changed

src/client/auth/plain.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ pub(crate) async fn authenticate_stream(
4646
}
4747

4848
fn payload_bytes(username: &str, password: &str) -> Vec<u8> {
49-
let mut bytes = Vec::new();
50-
51-
bytes.push(0);
49+
let mut bytes = vec![0];
5250
bytes.extend(username.as_bytes());
5351

5452
bytes.push(0);

src/sdam/description/topology/server_selection/test/mod.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,16 @@ struct LastWriteDate {
120120
enum TestServerType {
121121
Standalone,
122122
Mongos,
123-
RSPrimary,
124-
RSSecondary,
125-
RSArbiter,
126-
RSOther,
127-
RSGhost,
123+
#[serde(rename = "RSPrimary")]
124+
RsPrimary,
125+
#[serde(rename = "RSSecondary")]
126+
RsSecondary,
127+
#[serde(rename = "RSArbiter")]
128+
RsArbiter,
129+
#[serde(rename = "RSOther")]
130+
RsOther,
131+
#[serde(rename = "RSGhost")]
132+
RsGhost,
128133
Unknown,
129134
PossiblePrimary,
130135
}
@@ -134,11 +139,11 @@ impl TestServerType {
134139
match self {
135140
TestServerType::Standalone => Some(ServerType::Standalone),
136141
TestServerType::Mongos => Some(ServerType::Mongos),
137-
TestServerType::RSPrimary => Some(ServerType::RsPrimary),
138-
TestServerType::RSSecondary => Some(ServerType::RsSecondary),
139-
TestServerType::RSArbiter => Some(ServerType::RsArbiter),
140-
TestServerType::RSOther => Some(ServerType::RsOther),
141-
TestServerType::RSGhost => Some(ServerType::RsGhost),
142+
TestServerType::RsPrimary => Some(ServerType::RsPrimary),
143+
TestServerType::RsSecondary => Some(ServerType::RsSecondary),
144+
TestServerType::RsArbiter => Some(ServerType::RsArbiter),
145+
TestServerType::RsOther => Some(ServerType::RsOther),
146+
TestServerType::RsGhost => Some(ServerType::RsGhost),
142147
TestServerType::Unknown => Some(ServerType::Unknown),
143148
TestServerType::PossiblePrimary => None,
144149
}

src/selection_criteria.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ impl<'de> Deserialize<'de> for SelectionCriteria {
7878
where
7979
D: Deserializer<'de>,
8080
{
81-
Ok(SelectionCriteria::ReadPreference(ReadPreference::deserialize(deserializer)?))
81+
Ok(SelectionCriteria::ReadPreference(
82+
ReadPreference::deserialize(deserializer)?,
83+
))
8284
}
8385
}
8486

@@ -131,11 +133,22 @@ impl<'de> Deserialize<'de> for ReadPreference {
131133

132134
match preference.mode.as_str() {
133135
"Primary" => Ok(ReadPreference::Primary),
134-
"Secondary" => Ok(ReadPreference::Secondary { options: preference.options }),
135-
"PrimaryPreferred" => Ok(ReadPreference::PrimaryPreferred { options: preference.options }),
136-
"SecondaryPreferred" => Ok(ReadPreference::SecondaryPreferred { options: preference.options }),
137-
"Nearest" => Ok(ReadPreference::Nearest { options: preference.options }),
138-
other => Err(D::Error::custom(format!("Unknown read preference mode: {}", other))),
136+
"Secondary" => Ok(ReadPreference::Secondary {
137+
options: preference.options,
138+
}),
139+
"PrimaryPreferred" => Ok(ReadPreference::PrimaryPreferred {
140+
options: preference.options,
141+
}),
142+
"SecondaryPreferred" => Ok(ReadPreference::SecondaryPreferred {
143+
options: preference.options,
144+
}),
145+
"Nearest" => Ok(ReadPreference::Nearest {
146+
options: preference.options,
147+
}),
148+
other => Err(D::Error::custom(format!(
149+
"Unknown read preference mode: {}",
150+
other
151+
))),
139152
}
140153
}
141154
}
@@ -157,7 +170,10 @@ pub struct ReadPreferenceOptions {
157170
/// `max_staleness` must be at least 90 seconds. If a `max_staleness` less than 90 seconds is
158171
/// specified for an operation, the operation will return an error.
159172
#[builder(default)]
160-
#[serde(rename = "maxStalenessSeconds", deserialize_with = "deserialize_duration_from_u64_seconds")]
173+
#[serde(
174+
rename = "maxStalenessSeconds",
175+
deserialize_with = "deserialize_duration_from_u64_seconds"
176+
)]
161177
pub max_staleness: Option<Duration>,
162178

163179
/// Specifies hedging behavior for reads. These options only apply to sharded clusters on

src/test/spec/auth.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ struct TestCredential {
2222
pub mechanism_properties: Option<Document>,
2323
}
2424

25-
impl Into<Credential> for TestCredential {
26-
fn into(self) -> Credential {
27-
Credential {
28-
username: self.username,
29-
password: self.password,
30-
source: self.source,
31-
mechanism: self
25+
impl From<TestCredential> for Credential {
26+
fn from(test_credential: TestCredential) -> Self {
27+
Self {
28+
username: test_credential.username,
29+
password: test_credential.password,
30+
source: test_credential.source,
31+
mechanism: test_credential
3232
.mechanism
3333
.and_then(|s| AuthMechanism::from_str(s.as_str()).ok()),
34-
mechanism_properties: self.mechanism_properties,
34+
mechanism_properties: test_credential.mechanism_properties,
3535
}
3636
}
3737
}

src/test/spec/initial_dns_seedlist_discovery.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async fn run() {
6060
};
6161

6262
if let Some(true) = test_file.error {
63-
assert!(matches!(result, Err(_)), test_file.comment.unwrap());
63+
assert!(matches!(result, Err(_)), "{}", test_file.comment.unwrap());
6464
return;
6565
}
6666

src/test/spec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ where
7676
run_test_file(
7777
bson::from_bson(
7878
Bson::try_from(json)
79-
.unwrap_or_else(|_| panic!(test_file_full_path.display().to_string())),
79+
.unwrap_or_else(|_| panic!("{}", test_file_full_path.display().to_string())),
8080
)
8181
.unwrap_or_else(|e| panic!("{}: {}", test_file_full_path.display().to_string(), e)),
8282
)

src/test/spec/unified_runner/matcher.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ async fn array_matching() {
273273
None,
274274
));
275275

276-
let mut actual: Vec<Bson> = Vec::new();
277-
actual.push(Bson::Document(doc! { "x": 1, "y": 1 }));
278-
actual.push(Bson::Document(doc! { "x": 2, "y": 2 }));
279-
let mut expected: Vec<Bson> = Vec::new();
280-
expected.push(Bson::Document(doc! { "x": 1 }));
281-
expected.push(Bson::Document(doc! { "x": 2 }));
276+
let actual = vec![
277+
Bson::Document(doc! { "x": 1, "y": 1 }),
278+
Bson::Document(doc! { "x": 2, "y": 2 }),
279+
];
280+
let expected = vec![
281+
Bson::Document(doc! { "x": 1 }),
282+
Bson::Document(doc! { "x": 2 }),
283+
];
282284
assert!(!results_match(
283285
Some(&Bson::Array(actual)),
284286
&Bson::Array(expected),

0 commit comments

Comments
 (0)