Skip to content

Commit 6377436

Browse files
committed
Fix clippy
1 parent 8953239 commit 6377436

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub trait MysqlShim<W: Read + Write> {
207207
}
208208

209209
/// Information about an authenticated user
210-
#[derive(Debug, Default, Clone, PartialEq)]
210+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
211211
pub struct AuthenticationContext<'a> {
212212
/// The username exactly as passed by the client,
213213
pub username: Option<Vec<u8>>,

src/tls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(crate) struct SwitchableConn<T: Read + Write>(pub(crate) Option<EitherConn<T
1717

1818
pub(crate) enum EitherConn<T: Read + Write> {
1919
Plain(T),
20-
Tls(rustls::StreamOwned<ServerConnection, PrependedReader<T>>),
20+
Tls(Box<rustls::StreamOwned<ServerConnection, PrependedReader<T>>>),
2121
}
2222

2323
impl<T: Read + Write> Read for SwitchableConn<T> {
@@ -56,10 +56,10 @@ impl<T: Read + Write> SwitchableConn<T> {
5656
to_prepend: &[u8],
5757
) -> io::Result<()> {
5858
let replacement = match self.0.take() {
59-
Some(EitherConn::Plain(plain)) => Ok(EitherConn::Tls(create_stream(
59+
Some(EitherConn::Plain(plain)) => Ok(EitherConn::Tls(Box::new(create_stream(
6060
PrependedReader::new(to_prepend, plain),
6161
config,
62-
)?)),
62+
)?))),
6363
Some(EitherConn::Tls(_)) => Err(io::Error::new(
6464
io::ErrorKind::Other,
6565
"tls variant found when plain was expected",

src/value/decode.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,40 +206,44 @@ impl<'a> From<Value<'a>> for NaiveDate {
206206
fn from(val: Value<'a>) -> Self {
207207
if let ValueInner::Date(mut v) = val.0 {
208208
assert_eq!(v.len(), 4);
209-
NaiveDate::from_ymd(
209+
if let Some(d) = NaiveDate::from_ymd_opt(
210210
i32::from(v.read_u16::<LittleEndian>().unwrap()),
211211
u32::from(v.read_u8().unwrap()),
212212
u32::from(v.read_u8().unwrap()),
213-
)
214-
} else {
215-
panic!("invalid type conversion from {:?} to date", val)
213+
) {
214+
return d;
215+
}
216216
}
217+
panic!("invalid type conversion from {:?} to date", val)
217218
}
218219
}
219220

220221
impl<'a> From<Value<'a>> for NaiveDateTime {
221222
fn from(val: Value<'a>) -> Self {
222223
if let ValueInner::Datetime(mut v) = val.0 {
223224
assert!(v.len() == 7 || v.len() == 11);
224-
let d = NaiveDate::from_ymd(
225+
if let Some(d) = NaiveDate::from_ymd_opt(
225226
i32::from(v.read_u16::<LittleEndian>().unwrap()),
226227
u32::from(v.read_u8().unwrap()),
227228
u32::from(v.read_u8().unwrap()),
228-
);
229+
) {
230+
let h = u32::from(v.read_u8().unwrap());
231+
let m = u32::from(v.read_u8().unwrap());
232+
let s = u32::from(v.read_u8().unwrap());
229233

230-
let h = u32::from(v.read_u8().unwrap());
231-
let m = u32::from(v.read_u8().unwrap());
232-
let s = u32::from(v.read_u8().unwrap());
234+
let d = if v.len() == 11 {
235+
let us = v.read_u32::<LittleEndian>().unwrap();
236+
d.and_hms_micro_opt(h, m, s, us)
237+
} else {
238+
d.and_hms_opt(h, m, s)
239+
};
233240

234-
if v.len() == 11 {
235-
let us = v.read_u32::<LittleEndian>().unwrap();
236-
d.and_hms_micro(h, m, s, us)
237-
} else {
238-
d.and_hms(h, m, s)
241+
if let Some(d) = d {
242+
return d;
243+
}
239244
}
240-
} else {
241-
panic!("invalid type conversion from {:?} to datetime", val)
242245
}
246+
panic!("invalid type conversion from {:?} to datetime", val)
243247
}
244248
}
245249

@@ -438,13 +442,16 @@ mod tests {
438442
rt!(
439443
time,
440444
chrono::NaiveDate,
441-
chrono::Local::today().naive_local(),
445+
chrono::Local::now().date_naive(),
442446
ColumnType::MYSQL_TYPE_DATE
443447
);
444448
rt!(
445449
datetime,
446450
chrono::NaiveDateTime,
447-
chrono::Utc.ymd(1989, 12, 7).and_hms(8, 0, 4).naive_utc(),
451+
chrono::Utc
452+
.with_ymd_and_hms(1989, 12, 7, 8, 0, 4)
453+
.unwrap()
454+
.naive_utc(),
448455
ColumnType::MYSQL_TYPE_DATETIME
449456
);
450457
rt!(

src/value/encode.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ impl ToMysqlValue for [u8] {
392392

393393
impl ToMysqlValue for Vec<u8> {
394394
fn to_mysql_text<W: Write>(&self, w: &mut W) -> io::Result<()> {
395-
(&self[..]).to_mysql_text(w)
395+
(self[..]).to_mysql_text(w)
396396
}
397397
fn to_mysql_bin<W: Write>(&self, w: &mut W, c: &Column) -> io::Result<()> {
398-
(&self[..]).to_mysql_bin(w, c)
398+
(self[..]).to_mysql_bin(w, c)
399399
}
400400
}
401401

@@ -563,8 +563,10 @@ impl ToMysqlValue for myc::value::Value {
563563
myc::value::Value::Float(f) => f.to_mysql_text(w),
564564
myc::value::Value::Double(f) => f.to_mysql_text(w),
565565
myc::value::Value::Date(y, mo, d, h, mi, s, us) => {
566-
NaiveDate::from_ymd(i32::from(y), u32::from(mo), u32::from(d))
567-
.and_hms_micro(u32::from(h), u32::from(mi), u32::from(s), us)
566+
NaiveDate::from_ymd_opt(i32::from(y), u32::from(mo), u32::from(d))
567+
.unwrap_or_else(|| panic!("invalid date: y {} mo {} d {}", y, mo, d))
568+
.and_hms_micro_opt(u32::from(h), u32::from(mi), u32::from(s), us)
569+
.unwrap_or_else(|| panic!("invalid date: h {} mi {} s {} us {}", h, mi, s, us))
568570
.to_mysql_text(w)
569571
}
570572
myc::value::Value::Time(neg, d, h, m, s, us) => {
@@ -628,8 +630,10 @@ impl ToMysqlValue for myc::value::Value {
628630
myc::value::Value::Float(f) => f.to_mysql_bin(w, c),
629631
myc::value::Value::Double(f) => f.to_mysql_bin(w, c),
630632
myc::value::Value::Date(y, mo, d, h, mi, s, us) => {
631-
NaiveDate::from_ymd(i32::from(y), u32::from(mo), u32::from(d))
632-
.and_hms_micro(u32::from(h), u32::from(mi), u32::from(s), us)
633+
NaiveDate::from_ymd_opt(i32::from(y), u32::from(mo), u32::from(d))
634+
.unwrap_or_else(|| panic!("invalid date: y {} mo {} d {}", y, mo, d))
635+
.and_hms_micro_opt(u32::from(h), u32::from(mi), u32::from(s), us)
636+
.unwrap_or_else(|| panic!("invalid date: h {} mi {} s {} us {}", h, mi, s, us))
633637
.to_mysql_bin(w, c)
634638
}
635639
myc::value::Value::Time(neg, d, h, m, s, us) => {

0 commit comments

Comments
 (0)