Skip to content

Commit a388fea

Browse files
authored
Fix some clippy warnings (#32)
This fixes some clippy warnings to prevent the linter from complaining.
1 parent e77fd27 commit a388fea

File tree

6 files changed

+31
-38
lines changed

6 files changed

+31
-38
lines changed

src/commands.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::myc::constants::{CapabilityFlags, Command as CommandByte};
22

33
#[derive(Debug)]
4+
#[allow(dead_code)] // The fields here are read, but only in tests. This keeps clippy quiet.
45
pub struct ClientHandshake<'a> {
56
capabilities: CapabilityFlags,
67
maxps: u32,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
326326
let schema = ::std::str::from_utf8(&q[b"USE ".len()..])
327327
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
328328
let schema = schema.trim().trim_end_matches(';').trim_matches('`');
329-
self.shim.on_init(&schema, w)?;
329+
self.shim.on_init(schema, w)?;
330330
} else {
331331
let w = QueryResultWriter::new(&mut self.writer, false);
332332
self.shim.on_query(

src/packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ impl<R: Read> PacketReader<R> {
114114
let end = self.bytes.len();
115115
self.bytes.resize(std::cmp::max(4096, end * 2), 0);
116116
let read = {
117-
let mut buf = &mut self.bytes[end..];
118-
self.r.read(&mut buf)?
117+
let buf = &mut self.bytes[end..];
118+
self.r.read(buf)?
119119
};
120120
self.bytes.truncate(end + read);
121121
self.remaining = self.bytes.len();

src/resultset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a, W: Write + 'a> StatementMetaWriter<'a, W> {
7979

8080
enum Finalizer {
8181
Ok { rows: u64, last_insert_id: u64 },
82-
EOF,
82+
Eof,
8383
}
8484

8585
/// Convenience type for providing query results to clients.
@@ -127,7 +127,7 @@ impl<'a, W: Write> QueryResultWriter<'a, W> {
127127
rows,
128128
last_insert_id,
129129
}) => writers::write_ok_packet(self.writer, rows, last_insert_id, status),
130-
Some(Finalizer::EOF) => writers::write_eof_packet(self.writer, status),
130+
Some(Finalizer::Eof) => writers::write_eof_packet(self.writer, status),
131131
}
132132
}
133133

@@ -368,7 +368,7 @@ impl<'a, W: Write + 'a> RowWriter<'a, W> {
368368
});
369369
} else {
370370
// we wrote out at least one row
371-
self.result.as_mut().unwrap().last_end = Some(Finalizer::EOF);
371+
self.result.as_mut().unwrap().last_end = Some(Finalizer::Eof);
372372
}
373373
}
374374

src/value/decode.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ impl<'a> Value<'a> {
4949

5050
/// Returns true if this is a NULL value
5151
pub fn is_null(&self) -> bool {
52-
if let ValueInner::NULL = self.0 {
53-
true
54-
} else {
55-
false
56-
}
52+
matches!(self.0, ValueInner::NULL)
5753
}
5854

5955
pub(crate) fn parse_from(
@@ -169,12 +165,12 @@ impl<'a> ValueInner<'a> {
169165
}
170166
}
171167

172-
// NOTE: these should all be TryInto
168+
// NOTE: these should all be TryFrom
173169
macro_rules! impl_into {
174170
($t:ty, $($variant:path),*) => {
175-
impl<'a> Into<$t> for Value<'a> {
176-
fn into(self) -> $t {
177-
match self.0 {
171+
impl<'a> From<Value<'a>> for $t {
172+
fn from(val: Value<'a>) -> Self {
173+
match val.0 {
178174
$($variant(v) => v as $t),*,
179175
v => panic!(concat!("invalid type conversion from {:?} to ", stringify!($t)), v)
180176
}
@@ -195,35 +191,35 @@ impl_into!(f32, ValueInner::Double);
195191
impl_into!(f64, ValueInner::Double);
196192
impl_into!(&'a [u8], ValueInner::Bytes);
197193

198-
impl<'a> Into<&'a str> for Value<'a> {
199-
fn into(self) -> &'a str {
200-
if let ValueInner::Bytes(v) = self.0 {
194+
impl<'a> From<Value<'a>> for &'a str {
195+
fn from(val: Value<'a>) -> Self {
196+
if let ValueInner::Bytes(v) = val.0 {
201197
::std::str::from_utf8(v).unwrap()
202198
} else {
203-
panic!("invalid type conversion from {:?} to string", self)
199+
panic!("invalid type conversion from {:?} to string", val)
204200
}
205201
}
206202
}
207203

208204
use chrono::{NaiveDate, NaiveDateTime};
209-
impl<'a> Into<NaiveDate> for Value<'a> {
210-
fn into(self) -> NaiveDate {
211-
if let ValueInner::Date(mut v) = self.0 {
205+
impl<'a> From<Value<'a>> for NaiveDate {
206+
fn from(val: Value<'a>) -> Self {
207+
if let ValueInner::Date(mut v) = val.0 {
212208
assert_eq!(v.len(), 4);
213209
NaiveDate::from_ymd(
214210
i32::from(v.read_u16::<LittleEndian>().unwrap()),
215211
u32::from(v.read_u8().unwrap()),
216212
u32::from(v.read_u8().unwrap()),
217213
)
218214
} else {
219-
panic!("invalid type conversion from {:?} to date", self)
215+
panic!("invalid type conversion from {:?} to date", val)
220216
}
221217
}
222218
}
223219

224-
impl<'a> Into<NaiveDateTime> for Value<'a> {
225-
fn into(self) -> NaiveDateTime {
226-
if let ValueInner::Datetime(mut v) = self.0 {
220+
impl<'a> From<Value<'a>> for NaiveDateTime {
221+
fn from(val: Value<'a>) -> Self {
222+
if let ValueInner::Datetime(mut v) = val.0 {
227223
assert!(v.len() == 7 || v.len() == 11);
228224
let d = NaiveDate::from_ymd(
229225
i32::from(v.read_u16::<LittleEndian>().unwrap()),
@@ -242,18 +238,18 @@ impl<'a> Into<NaiveDateTime> for Value<'a> {
242238
d.and_hms(h, m, s)
243239
}
244240
} else {
245-
panic!("invalid type conversion from {:?} to datetime", self)
241+
panic!("invalid type conversion from {:?} to datetime", val)
246242
}
247243
}
248244
}
249245

250246
use std::time::Duration;
251-
impl<'a> Into<Duration> for Value<'a> {
252-
fn into(self) -> Duration {
253-
if let ValueInner::Time(mut v) = self.0 {
254-
assert!(v.len() == 0 || v.len() == 8 || v.len() == 12);
247+
impl<'a> From<Value<'a>> for Duration {
248+
fn from(val: Value<'a>) -> Self {
249+
if let ValueInner::Time(mut v) = val.0 {
250+
assert!(v.is_empty() || v.len() == 8 || v.len() == 12);
255251

256-
if v.len() == 0 {
252+
if v.is_empty() {
257253
return Duration::from_secs(0);
258254
}
259255

@@ -277,7 +273,7 @@ impl<'a> Into<Duration> for Value<'a> {
277273
micros * 1_000,
278274
)
279275
} else {
280-
panic!("invalid type conversion from {:?} to datetime", self)
276+
panic!("invalid type conversion from {:?} to datetime", val)
281277
}
282278
}
283279
}

src/value/encode.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,7 @@ impl ToMysqlValue for myc::value::Value {
653653
}
654654

655655
fn is_null(&self) -> bool {
656-
if let myc::value::Value::NULL = *self {
657-
true
658-
} else {
659-
false
660-
}
656+
matches!(*self, myc::value::Value::NULL)
661657
}
662658
}
663659

0 commit comments

Comments
 (0)