Skip to content

Commit efbbe9a

Browse files
committed
clippy clean
1 parent 97d7622 commit efbbe9a

File tree

4 files changed

+49
-42
lines changed

4 files changed

+49
-42
lines changed

src/errorcodes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,8 +2816,8 @@ impl ErrorKind {
28162816
/// conditions within the class. `000` means 'no subclass'.
28172817
///
28182818
/// See also https://mariadb.com/kb/en/library/sqlstate/
2819-
pub fn sqlstate(&self) -> &'static [u8; 5] {
2820-
match *self {
2819+
pub fn sqlstate(self) -> &'static [u8; 5] {
2820+
match self {
28212821
ErrorKind::ER_BAD_HOST_ERROR
28222822
| ErrorKind::ER_HANDSHAKE_ERROR
28232823
| ErrorKind::ER_UNKNOWN_COM_ERROR

src/lib.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,12 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
308308
)?;
309309
}
310310
Command::Execute { stmt, params } => {
311-
let state = stmts.get_mut(&stmt).ok_or(io::Error::new(
312-
io::ErrorKind::InvalidData,
313-
format!("asked to execute unknown statement {}", stmt),
314-
))?;
311+
let state = stmts.get_mut(&stmt).ok_or_else(|| {
312+
io::Error::new(
313+
io::ErrorKind::InvalidData,
314+
format!("asked to execute unknown statement {}", stmt),
315+
)
316+
})?;
315317
{
316318
let params = params::ParamParser::new(params, state);
317319
let w = QueryResultWriter::new(&mut self.writer, true);
@@ -322,10 +324,12 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
322324
Command::SendLongData { stmt, param, data } => {
323325
stmts
324326
.get_mut(&stmt)
325-
.ok_or(io::Error::new(
326-
io::ErrorKind::InvalidData,
327-
format!("got long data packet for unknown statement {}", stmt),
328-
))?
327+
.ok_or_else(|| {
328+
io::Error::new(
329+
io::ErrorKind::InvalidData,
330+
format!("got long data packet for unknown statement {}", stmt),
331+
)
332+
})?
329333
.long_data
330334
.entry(param)
331335
.or_insert_with(Vec::new)

src/resultset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ pub struct QueryResultWriter<'a, W: Write + 'a> {
110110
impl<'a, W: Write> QueryResultWriter<'a, W> {
111111
pub(crate) fn new(writer: &'a mut PacketWriter<W>, is_bin: bool) -> Self {
112112
QueryResultWriter {
113-
is_bin: is_bin,
114-
writer: writer,
113+
is_bin,
114+
writer,
115115
last_end: None,
116116
}
117117
}
@@ -219,7 +219,7 @@ where
219219
let bitmap_len = (columns.len() + 7 + 2) / 8;
220220
let mut rw = RowWriter {
221221
result: Some(result),
222-
columns: columns,
222+
columns,
223223
bitmap_len,
224224
data: Vec::new(),
225225

src/value/encode.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ impl ToMysqlValue for Duration {
504504
let h = s / 3600;
505505
let m = (s % 3600) / 60;
506506
let s = s % 60;
507-
let us = self.subsec_nanos() / 1_000;
507+
let us = self.subsec_micros();
508508
if us != 0 {
509509
w.write_lenenc_str(format!("{:02}:{:02}:{:02}.{:06}", h, m, s, us).as_bytes())
510510
.map(|_| ())
@@ -513,14 +513,16 @@ impl ToMysqlValue for Duration {
513513
.map(|_| ())
514514
}
515515
}
516+
517+
#[allow(clippy::many_single_char_names)]
516518
fn to_mysql_bin<W: Write>(&self, w: &mut W, c: &Column) -> io::Result<()> {
517519
let s = self.as_secs();
518520
let d = s / (24 * 3600);
519521
assert!(d <= 34);
520522
let h = (s % (24 * 3600)) / 3600;
521523
let m = (s % 3600) / 60;
522524
let s = s % 60;
523-
let us = self.subsec_nanos() / 1_000;
525+
let us = self.subsec_micros();
524526

525527
match c.coltype {
526528
ColumnType::MYSQL_TYPE_TIME => {
@@ -547,6 +549,7 @@ impl ToMysqlValue for Duration {
547549
}
548550

549551
impl ToMysqlValue for myc::value::Value {
552+
#[allow(clippy::many_single_char_names)]
550553
fn to_mysql_text<W: Write>(&self, w: &mut W) -> io::Result<()> {
551554
match *self {
552555
myc::value::Value::NULL => None::<u8>.to_mysql_text(w),
@@ -555,8 +558,8 @@ impl ToMysqlValue for myc::value::Value {
555558
myc::value::Value::UInt(n) => n.to_mysql_text(w),
556559
myc::value::Value::Float(f) => f.to_mysql_text(w),
557560
myc::value::Value::Date(y, mo, d, h, mi, s, us) => {
558-
NaiveDate::from_ymd(y as i32, mo as u32, d as u32)
559-
.and_hms_micro(h as u32, mi as u32, s as u32, us)
561+
NaiveDate::from_ymd(i32::from(y), u32::from(mo), u32::from(d))
562+
.and_hms_micro(u32::from(h), u32::from(mi), u32::from(s), us)
560563
.to_mysql_text(w)
561564
}
562565
myc::value::Value::Time(neg, d, h, m, s, us) => {
@@ -566,17 +569,19 @@ impl ToMysqlValue for myc::value::Value {
566569
"negative times not yet supported",
567570
));
568571
}
569-
(chrono::Duration::days(d as i64)
570-
+ chrono::Duration::hours(h as i64)
571-
+ chrono::Duration::minutes(m as i64)
572-
+ chrono::Duration::seconds(s as i64)
573-
+ chrono::Duration::microseconds(us as i64))
572+
(chrono::Duration::days(i64::from(d))
573+
+ chrono::Duration::hours(i64::from(h))
574+
+ chrono::Duration::minutes(i64::from(m))
575+
+ chrono::Duration::seconds(i64::from(s))
576+
+ chrono::Duration::microseconds(i64::from(us)))
574577
.to_std()
575578
.expect("only positive times at the moment")
576579
.to_mysql_text(w)
577580
}
578581
}
579582
}
583+
584+
#[allow(clippy::many_single_char_names)]
580585
fn to_mysql_bin<W: Write>(&self, w: &mut W, c: &Column) -> io::Result<()> {
581586
match *self {
582587
myc::value::Value::NULL => unreachable!(),
@@ -589,28 +594,26 @@ impl ToMysqlValue for myc::value::Value {
589594
// smallest containing type, and then call on that
590595
let signed = !c.colflags.contains(ColumnFlags::UNSIGNED_FLAG);
591596
if signed {
592-
if n >= i8::min_value() as i64 && n <= i8::max_value() as i64 {
597+
if n >= i64::from(i8::min_value()) && n <= i64::from(i8::max_value()) {
593598
(n as i8).to_mysql_bin(w, c)
594-
} else if n >= i16::min_value() as i64 && n <= i16::max_value() as i64 {
599+
} else if n >= i64::from(i16::min_value()) && n <= i64::from(i16::max_value()) {
595600
(n as i16).to_mysql_bin(w, c)
596-
} else if n >= i32::min_value() as i64 && n <= i32::max_value() as i64 {
601+
} else if n >= i64::from(i32::min_value()) && n <= i64::from(i32::max_value()) {
597602
(n as i32).to_mysql_bin(w, c)
598603
} else {
599604
n.to_mysql_bin(w, c)
600605
}
601606
} else if n < 0 {
602607
Err(bad(self, c))
608+
} else if n <= i64::from(u8::max_value()) {
609+
(n as u8).to_mysql_bin(w, c)
610+
} else if n <= i64::from(u16::max_value()) {
611+
(n as u16).to_mysql_bin(w, c)
612+
} else if n <= i64::from(u32::max_value()) {
613+
(n as u32).to_mysql_bin(w, c)
603614
} else {
604-
if n <= u8::max_value() as i64 {
605-
(n as u8).to_mysql_bin(w, c)
606-
} else if n <= u16::max_value() as i64 {
607-
(n as u16).to_mysql_bin(w, c)
608-
} else if n <= u32::max_value() as i64 {
609-
(n as u32).to_mysql_bin(w, c)
610-
} else {
611-
// must work since u64::max_value() > i64::max_value(), and n >= 0
612-
(n as u64).to_mysql_bin(w, c)
613-
}
615+
// must work since u64::max_value() > i64::max_value(), and n >= 0
616+
(n as u64).to_mysql_bin(w, c)
614617
}
615618
}
616619
myc::value::Value::UInt(n) => {
@@ -619,8 +622,8 @@ impl ToMysqlValue for myc::value::Value {
619622
}
620623
myc::value::Value::Float(f) => f.to_mysql_bin(w, c),
621624
myc::value::Value::Date(y, mo, d, h, mi, s, us) => {
622-
NaiveDate::from_ymd(y as i32, mo as u32, d as u32)
623-
.and_hms_micro(h as u32, mi as u32, s as u32, us)
625+
NaiveDate::from_ymd(i32::from(y), u32::from(mo), u32::from(d))
626+
.and_hms_micro(u32::from(h), u32::from(mi), u32::from(s), us)
624627
.to_mysql_bin(w, c)
625628
}
626629
myc::value::Value::Time(neg, d, h, m, s, us) => {
@@ -630,11 +633,11 @@ impl ToMysqlValue for myc::value::Value {
630633
"negative times not yet supported",
631634
));
632635
}
633-
(chrono::Duration::days(d as i64)
634-
+ chrono::Duration::hours(h as i64)
635-
+ chrono::Duration::minutes(m as i64)
636-
+ chrono::Duration::seconds(s as i64)
637-
+ chrono::Duration::microseconds(us as i64))
636+
(chrono::Duration::days(i64::from(d))
637+
+ chrono::Duration::hours(i64::from(h))
638+
+ chrono::Duration::minutes(i64::from(m))
639+
+ chrono::Duration::seconds(i64::from(s))
640+
+ chrono::Duration::microseconds(i64::from(us)))
638641
.to_std()
639642
.expect("only positive times at the moment")
640643
.to_mysql_bin(w, c)

0 commit comments

Comments
 (0)