@@ -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
549551impl 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