Skip to content

Commit 42bba3a

Browse files
committed
fix: more clippy warnings in mysql modules
- Fix explicit_auto_deref in mysql/options/parse.rs and mysql/transaction.rs - Replace manual Default impl with derive for MySqlSslMode - Add allow for enum_variant_names in AuthPlugin (breaking change to fix) - Fix get_first by using first() instead of get(0) - Fix unnecessary_cast by removing redundant casts - Fix map_clone by using copied() method in row and statement modules
1 parent 0715089 commit 42bba3a

File tree

8 files changed

+11
-14
lines changed

8 files changed

+11
-14
lines changed

sqlx-core/src/mysql/options/parse.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl FromStr for MySqlConnectOptions {
3030

3131
if let Some(password) = url.password() {
3232
options = options.password(
33-
&*percent_decode_str(password)
33+
&percent_decode_str(password)
3434
.decode_utf8()
3535
.map_err(Error::config)?,
3636
);
@@ -52,11 +52,11 @@ impl FromStr for MySqlConnectOptions {
5252
}
5353

5454
"charset" => {
55-
options = options.charset(&*value);
55+
options = options.charset(&value);
5656
}
5757

5858
"collation" => {
59-
options = options.collation(&*value);
59+
options = options.collation(&value);
6060
}
6161

6262
"statement-cache-capacity" => {

sqlx-core/src/mysql/options/ssl_mode.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::FromStr;
44
/// Options for controlling the desired security state of the connection to the MySQL server.
55
///
66
/// It is used by the [`ssl_mode`](super::MySqlConnectOptions::ssl_mode) method.
7-
#[derive(Debug, Clone, Copy)]
7+
#[derive(Debug, Clone, Copy, Default)]
88
pub enum MySqlSslMode {
99
/// Establish an unencrypted connection.
1010
Disabled,
@@ -13,6 +13,7 @@ pub enum MySqlSslMode {
1313
/// back to an unencrypted connection if an encrypted connection cannot be established.
1414
///
1515
/// This is the default if `ssl_mode` is not specified.
16+
#[default]
1617
Preferred,
1718

1819
/// Establish an encrypted connection if the server supports encrypted connections.
@@ -30,11 +31,6 @@ pub enum MySqlSslMode {
3031
VerifyIdentity,
3132
}
3233

33-
impl Default for MySqlSslMode {
34-
fn default() -> Self {
35-
MySqlSslMode::Preferred
36-
}
37-
}
3834

3935
impl FromStr for MySqlSslMode {
4036
type Err = Error;

sqlx-core/src/mysql/protocol/auth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::str::FromStr;
33
use crate::error::Error;
44

55
#[derive(Debug, Copy, Clone)]
6+
#[allow(clippy::enum_variant_names)]
67
pub enum AuthPlugin {
78
MySqlNativePassword,
89
CachingSha2Password,

sqlx-core/src/mysql/protocol/response/err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Decode<'_, Capabilities> for ErrPacket {
3030

3131
if capabilities.contains(Capabilities::PROTOCOL_41) {
3232
// If the next byte is '#' then we have a SQL STATE
33-
if buf.get(0) == Some(&0x23) {
33+
if buf.first() == Some(&0x23) {
3434
buf.advance(1);
3535
sql_state = Some(buf.get_str(5)?);
3636
}

sqlx-core/src/mysql/protocol/row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ impl Row {
1212
pub(crate) fn get(&self, index: usize) -> Option<&[u8]> {
1313
self.values[index]
1414
.as_ref()
15-
.map(|col| &self.storage[(col.start as usize)..(col.end as usize)])
15+
.map(|col| &self.storage[col.start..col.end])
1616
}
1717
}

sqlx-core/src/mysql/row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ impl ColumnIndex<MySqlRow> for &'_ str {
4545
fn index(&self, row: &MySqlRow) -> Result<usize, Error> {
4646
row.column_names
4747
.get(*self)
48+
.copied()
4849
.ok_or_else(|| Error::ColumnNotFound((*self).into()))
49-
.map(|v| *v)
5050
}
5151
}
5252

sqlx-core/src/mysql/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ impl ColumnIndex<MySqlStatement<'_>> for &'_ str {
5353
.metadata
5454
.column_names
5555
.get(*self)
56+
.copied()
5657
.ok_or_else(|| Error::ColumnNotFound((*self).into()))
57-
.map(|v| *v)
5858
}
5959
}
6060

sqlx-core/src/mysql/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl TransactionManager for MySqlTransactionManager {
6060
conn.stream.waiting.push_back(Waiting::Result);
6161
conn.stream.sequence_id = 0;
6262
conn.stream
63-
.write_packet(Query(&*rollback_ansi_transaction_sql(depth)));
63+
.write_packet(Query(&rollback_ansi_transaction_sql(depth)));
6464

6565
conn.transaction_depth = depth - 1;
6666
}

0 commit comments

Comments
 (0)