| 1 | //! The [`MysqlTime`] type. |
| 2 | |
| 3 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::textrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/::ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#; |
| 4 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::{MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#, MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#, MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#}; |
| 5 | use bytesrust-analyzer cargo bytes 1.12.1 crate/::{Bufrust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#, BufMutrust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#}; |
| 6 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::databaserust-analyzer cargo sqlx-core 0.8.3 database/::Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#; |
| 7 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::decoderust-analyzer cargo sqlx-core 0.8.3 decode/::Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#; |
| 8 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::encoderust-analyzer cargo sqlx-core 0.8.3 encode/::{Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#, IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#}; |
| 9 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::errorrust-analyzer cargo sqlx-core 0.8.3 error/::BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#; |
| 10 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::typesrust-analyzer cargo sqlx-core 0.8.3 types/::Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#; |
| 11 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#; |
| 12 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#}; |
| 13 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#; |
| 14 | |
| 15 | // Similar to `PgInterval` |
| 16 | /// Container for a MySQL `TIME` value, which may be an interval or a time-of-day. |
| 17 | /// |
| 18 | /// Allowed range is `-838:59:59.0` to `838:59:59.0`. |
| 19 | /// |
| 20 | /// If this value is used for a time-of-day, the range should be `00:00:00.0` to `23:59:59.999999`. |
| 21 | /// You can use [`Self::is_valid_time_of_day()`] to check this easily. |
| 22 | /// |
| 23 | /// * [MySQL Manual 13.2.3: The TIME Type](https://dev.mysql.com/doc/refman/8.3/en/time.html) |
| 24 | /// * [MariaDB Manual: TIME](https://mariadb.com/kb/en/time/) |
| 25 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 26 | pub struct MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 27 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign.: MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#, |
| 28 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.: TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#, |
| 29 | } |
| 30 | |
| 31 | // By using a subcontainer for the actual time magnitude, |
| 32 | // we can still use a derived `Ord` implementation and just flip the comparison for negative values. |
| 33 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 34 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) struct TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude# { |
| 35 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#hours.: u32, |
| 36 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#minutes.: u8, |
| 37 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#seconds.: u8, |
| 38 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#microseconds.: u32, |
| 39 | } |
| 40 | |
| 41 | const MAGNITUDE_ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MAGNITUDE_ZERO.: TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude# = TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude# { |
| 42 | hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#hours.: 0, |
| 43 | minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#minutes.: 0, |
| 44 | secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#seconds.: 0, |
| 45 | microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#microseconds.: 0, |
| 46 | }; |
| 47 | |
| 48 | /// Maximum magnitude (positive or negative). |
| 49 | const MAGNITUDE_MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MAGNITUDE_MAX.: TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude# = TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude# { |
| 50 | hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#hours.: MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::HOURS_MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]HOURS_MAX., |
| 51 | minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#minutes.: 59, |
| 52 | secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#seconds.: 59, |
| 53 | // Surprisingly this is not 999_999 which is why `MySqlTimeError::SubsecondExcess`. |
| 54 | microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#microseconds.: 0, |
| 55 | }; |
| 56 | |
| 57 | /// The sign for a [`MySqlTime`] type. |
| 58 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 59 | pub enum MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign# { |
| 60 | // The protocol actually specifies negative as 1 and positive as 0, |
| 61 | // but by specifying variants this way we can derive `Ord` and it works as expected. |
| 62 | /// The interval is negative (invalid for time-of-day values). |
| 63 | Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative#, |
| 64 | /// The interval is positive, or represents a time-of-day. |
| 65 | Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive#, |
| 66 | } |
| 67 | |
| 68 | /// Errors returned by [`MySqlTime::new()`]. |
| 69 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, thiserrorrust-analyzer cargo thiserror 2.0.20 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.20 Error:)] |
| 70 | pub enum MySqlTimeErrorrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError# { |
| 71 | /// A field of [`MySqlTime`] exceeded its max range. |
| 72 | #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("`MySqlTime` field `{field}` cannot exceed {max}, got {value}")] |
| 73 | FieldRangerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#FieldRange# { |
| 74 | fieldrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#FieldRange#field.: &'static str, |
| 75 | maxrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#FieldRange#max.: u32, |
| 76 | valuerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#FieldRange#value.: u64, |
| 77 | }, |
| 78 | /// Error returned for time magnitudes (positive or negative) between `838:59:59.0` and `839:00:00.0`. |
| 79 | /// |
| 80 | /// Other range errors should be covered by [`Self::FieldRange`] for the `hours` field. |
| 81 | /// |
| 82 | /// For applications which can tolerate rounding, a valid truncated value is provided. |
| 83 | #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:( |
| 84 | "`MySqlTime` cannot exceed +/-838:59:59.000000; got {sign}838:59:59.{microseconds:06}" |
| 85 | )] |
| 86 | SubsecondExcessrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#SubsecondExcess# { |
| 87 | /// The sign of the magnitude. |
| 88 | signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#SubsecondExcess#sign.: MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#, |
| 89 | /// The number of microseconds over the maximum. |
| 90 | microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#SubsecondExcess#microseconds.: u32, |
| 91 | /// The truncated value, |
| 92 | /// either [`MySqlTime::MIN`] if negative or [`MySqlTime::MAX`] if positive. |
| 93 | truncatedrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#SubsecondExcess#truncated.: MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#, |
| 94 | }, |
| 95 | /// MySQL coerces `-00:00:00` to `00:00:00` but this API considers that an error. |
| 96 | /// |
| 97 | /// For applications which can tolerate coercion, you can convert this error to [`MySqlTime::ZERO`]. |
| 98 | #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("attempted to construct a `MySqlTime` value of negative zero")] |
| 99 | NegativeZerorust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#NegativeZero#, |
| 100 | } |
| 101 | |
| 102 | impl MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 103 | /// The `MySqlTime` value corresponding to `TIME '0:00:00.0'` (zero). |
| 104 | pub const ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]ZERO.: Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime] = MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 105 | signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign.: MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive#, |
| 106 | magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.: MAGNITUDE_ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MAGNITUDE_ZERO., |
| 107 | }; |
| 108 | |
| 109 | /// The `MySqlTime` value corresponding to `TIME '838:59:59.0'` (max value). |
| 110 | pub const MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.: Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime] = MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 111 | signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign.: MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive#, |
| 112 | magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.: MAGNITUDE_MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MAGNITUDE_MAX., |
| 113 | }; |
| 114 | |
| 115 | /// The `MySqlTime` value corresponding to `TIME '-838:59:59.0'` (min value). |
| 116 | pub const MINrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MIN.: Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime] = MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 117 | signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign.: MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative#, |
| 118 | // Same magnitude, opposite sign. |
| 119 | magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.: MAGNITUDE_MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MAGNITUDE_MAX., |
| 120 | }; |
| 121 | |
| 122 | // The maximums for the other values are self-evident, but not necessarily this one. |
| 123 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) const HOURS_MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]HOURS_MAX.: u32 = 838; |
| 124 | |
| 125 | /// Construct a [`MySqlTime`] that is valid for use as a `TIME` value. |
| 126 | /// |
| 127 | /// ### Errors |
| 128 | /// * [`MySqlTimeError::NegativeZero`] if all fields are 0 but `sign` is [`MySqlTimeSign::Negative`]. |
| 129 | /// * [`MySqlTimeError::FieldRange`] if any field is out of range: |
| 130 | /// * `hours > 838` |
| 131 | /// * `minutes > 59` |
| 132 | /// * `seconds > 59` |
| 133 | /// * `microseconds > 999_999` |
| 134 | /// * [`MySqlTimeError::SubsecondExcess`] if the magnitude is less than one second over the maximum. |
| 135 | /// * Durations 839 hours or greater are covered by `FieldRange`. |
| 136 | pub fn newrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]new().( |
| 137 | sign: MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#, |
| 138 | hours: u32, |
| 139 | minutes: u8, |
| 140 | seconds: u8, |
| 141 | microseconds: u32, |
| 142 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime], MySqlTimeErrorrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#> { |
| 143 | macro_rules! check_fieldsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/check_fields! { |
| 144 | ($($name:ident: $max:expr),+ $(,)?) => { |
| 145 | $( |
| 146 | if $name > $max { |
| 147 | return Err(MySqlTimeError::FieldRange { |
| 148 | field: stringify!($name), |
| 149 | max: $max as u32, |
| 150 | value: $name as u64 |
| 151 | }) |
| 152 | } |
| 153 | )+ |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | check_fieldsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/check_fields!!( |
| 158 | hours: Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]::HOURS_MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]HOURS_MAX., |
| 159 | minutes: 59, |
| 160 | seconds: 59, |
| 161 | microseconds: 999_999 |
| 162 | ); |
| 163 | |
| 164 | let values = TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude# { |
| 165 | hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#hours., |
| 166 | minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#minutes., |
| 167 | secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#seconds., |
| 168 | microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#microseconds., |
| 169 | }; |
| 170 | |
| 171 | if sign.is_negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]is_negative().() && values rust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[TimeMagnitude][`PartialEq<Self>`]eq().==rust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[TimeMagnitude][`PartialEq<Self>`]eq(). rust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[TimeMagnitude][`PartialEq<Self>`]eq().MAGNITUDE_ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MAGNITUDE_ZERO. { |
| 172 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(MySqlTimeErrorrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#::NegativeZerorust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#NegativeZero#); |
| 173 | } |
| 174 | |
| 175 | // This is only `true` if less than 1 second over the maximum magnitude |
| 176 | if values rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().MAGNITUDE_MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MAGNITUDE_MAX. { |
| 177 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(MySqlTimeErrorrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#::SubsecondExcessrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#SubsecondExcess# { |
| 178 | signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#SubsecondExcess#sign., |
| 179 | microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#SubsecondExcess#microseconds., |
| 180 | truncatedrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#SubsecondExcess#truncated.: if sign.is_positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]is_positive().() { |
| 181 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX. |
| 182 | } else { |
| 183 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]::MINrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MIN. |
| 184 | }, |
| 185 | }); |
| 186 | } |
| 187 | |
| 188 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime] { |
| 189 | signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign., |
| 190 | magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.: values, |
| 191 | }) |
| 192 | } |
| 193 | |
| 194 | /// Update the `sign` of this value. |
| 195 | pub fn with_signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]with_sign().(self, sign: MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#) -> Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime] { |
| 196 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime] { signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign., ..self } |
| 197 | } |
| 198 | |
| 199 | /// Return the sign (positive or negative) for this TIME value. |
| 200 | pub fn signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]sign().(&self) -> MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign# { |
| 201 | self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign. |
| 202 | } |
| 203 | |
| 204 | /// Returns `true` if `self` is zero (equal to [`Self::ZERO`]). |
| 205 | pub fn is_zerorust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]is_zero().(&self) -> bool { |
| 206 | self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().&Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]::ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]ZERO. |
| 207 | } |
| 208 | |
| 209 | /// Returns `true` if `self` is positive or zero, `false` if negative. |
| 210 | pub fn is_positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]is_positive().(&self) -> bool { |
| 211 | self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign..is_positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]is_positive().() |
| 212 | } |
| 213 | |
| 214 | /// Returns `true` if `self` is negative, `false` if positive or zero. |
| 215 | pub fn is_negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]is_negative().(&self) -> bool { |
| 216 | self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign..is_positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]is_positive().() |
| 217 | } |
| 218 | |
| 219 | /// Returns `true` if this interval is a valid time-of-day. |
| 220 | /// |
| 221 | /// If `true`, the sign is positive and `hours` is not greater than 23. |
| 222 | pub fn is_valid_time_of_dayrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]is_valid_time_of_day().(&self) -> bool { |
| 223 | self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign..is_positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]is_positive().() && self.hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]hours().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().24 |
| 224 | } |
| 225 | |
| 226 | /// Get the total number of hours in this interval, from 0 to 838. |
| 227 | /// |
| 228 | /// If this value represents a time-of-day, the range is 0 to 23. |
| 229 | pub fn hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]hours().(&self) -> u32 { |
| 230 | self.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude..hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#hours. |
| 231 | } |
| 232 | |
| 233 | /// Get the number of minutes in this interval, from 0 to 59. |
| 234 | pub fn minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]minutes().(&self) -> u8 { |
| 235 | self.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude..minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#minutes. |
| 236 | } |
| 237 | |
| 238 | /// Get the number of seconds in this interval, from 0 to 59. |
| 239 | pub fn secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]seconds().(&self) -> u8 { |
| 240 | self.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude..secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#seconds. |
| 241 | } |
| 242 | |
| 243 | /// Get the number of seconds in this interval, from 0 to 999,999. |
| 244 | pub fn microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]microseconds().(&self) -> u32 { |
| 245 | self.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude..microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#microseconds. |
| 246 | } |
| 247 | |
| 248 | /// Convert this TIME value to a [`std::time::Duration`]. |
| 249 | /// |
| 250 | /// Returns `None` if this value is negative (cannot be represented). |
| 251 | pub fn to_durationrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]to_duration().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#> { |
| 252 | self.is_positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]is_positive().() |
| 253 | .thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(|| Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]new().(self.whole_secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]whole_seconds().() as u64, self.subsec_nanosrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]subsec_nanos().())) |
| 254 | } |
| 255 | |
| 256 | /// Get the whole number of seconds (`seconds + (minutes * 60) + (hours * 3600)`) in this time. |
| 257 | /// |
| 258 | /// Sign is ignored. |
| 259 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) fn whole_secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]whole_seconds().(&self) -> u32 { |
| 260 | // If `hours` does not exceed 838 then this cannot overflow. |
| 261 | self.hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]hours().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().3600 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().self.minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]minutes().() as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().self.secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]seconds().() as u32 |
| 262 | } |
| 263 | |
| 264 | #[cfg_attr(not(any(feature = "time", feature = "chrono")), allow(dead_code))] |
| 265 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) fn whole_seconds_signedrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]whole_seconds_signed().(&self) -> i64 { |
| 266 | self.whole_secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]whole_seconds().() as i64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign..signumrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]signum().() as i64 |
| 267 | } |
| 268 | |
| 269 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) fn subsec_nanosrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]subsec_nanos().(&self) -> u32 { |
| 270 | self.microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]microseconds().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().1000 |
| 271 | } |
| 272 | |
| 273 | fn encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]encoded_len().(&self) -> u8 { |
| 274 | if self.is_zerorust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]is_zero().() { |
| 275 | 0 |
| 276 | } else if self.microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]microseconds().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 { |
| 277 | 8 |
| 278 | } else { |
| 279 | 12 |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#<MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#> for MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 285 | fn partial_cmprust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`PartialOrd<Self>`]partial_cmp().(&self, other: &MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> { |
| 286 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.cmprust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][Ord]cmp().(other)) |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | impl Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 291 | fn cmprust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][Ord]cmp().(&self, other: &Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][Ord]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# { |
| 292 | // If the sides have different signs, we just need to compare those. |
| 293 | if self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().other.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign. { |
| 294 | return self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign..cmprust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign][Ord]cmp().(&other.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign.); |
| 295 | } |
| 296 | |
| 297 | // We've checked that both sides have the same sign |
| 298 | match self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign. { |
| 299 | MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive# => self.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude..cmprust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[TimeMagnitude][Ord]cmp().(&other.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.), |
| 300 | // Reverse the comparison for negative values (smaller negative magnitude = greater) |
| 301 | MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative# => other.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude..cmprust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[TimeMagnitude][Ord]cmp().(&self.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.), |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 307 | fn fmtrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][Display]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 308 | let TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude# { |
| 309 | hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#hours., |
| 310 | minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#minutes., |
| 311 | secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#seconds., |
| 312 | microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#microseconds., |
| 313 | } = self.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.; |
| 314 | |
| 315 | // Obeys the `+` flag. |
| 316 | Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign][Display]fmt().(&self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]sign().(), f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 317 | |
| 318 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{hours}:{minutes:02}:{seconds:02}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 319 | |
| 320 | // Write microseconds if not zero or a nonzero precision was explicitly requested. |
| 321 | if f.precisionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]precision().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(microseconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0, |it| it rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0) { |
| 322 | f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('.')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 323 | |
| 324 | let mut remaining_precision = f.precisionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]precision().(); |
| 325 | let mut remainder = microseconds; |
| 326 | let mut power_of_10 = 10u32.powrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]pow().(5); |
| 327 | |
| 328 | // Write digits from most-significant to least, up to the requested precision. |
| 329 | while remainder rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0 && remaining_precision rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0) { |
| 330 | let digit = remainder rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().power_of_10; |
| 331 | // 1 % 1 = 0 |
| 332 | remainder rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().power_of_10; |
| 333 | power_of_10 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`DivAssign<Self>`]div_assign().10; |
| 334 | |
| 335 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{digit}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 336 | |
| 337 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(remaining_precision) = &mut remaining_precision { |
| 338 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().remaining_precision = remaining_precision.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // If any requested precision remains, pad with zeroes. |
| 343 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(precision) = remaining_precision.filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]filter().(|it| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().it rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0) { |
| 344 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{:0precision$}", 0)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 353 | fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Type<MySql>`]type_info().() -> MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo# { |
| 354 | MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#::binaryrust-analyzer cargo sqlx-mysql 0.8.3 type_info/impl#[MySqlTypeInfo]binary().(ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Timerust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Time#) |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 359 | fn decoderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Decode<'r, MySql>`]decode().(value: <MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql# as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::ValueRefrust-analyzer cargo sqlx-core 0.8.3 database/Database#ValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Decode<'r, MySql>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 360 | match value.formatrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]format().() { |
| 361 | MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#::Binaryrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Binary# => { |
| 362 | let mut buf = value.as_bytesrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]as_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 363 | |
| 364 | // Row decoding should have left the length byte on the front. |
| 365 | if buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 366 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("empty buffer".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 367 | } |
| 368 | |
| 369 | let length = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().(); |
| 370 | |
| 371 | // MySQL specifies that if all fields are 0 then the length is 0 and no further data is sent |
| 372 | // https://dev.mysql.com/doc/internals/en/binary-protocol-value.html |
| 373 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 374 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Decode<'r, MySql>`]::ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]ZERO.); |
| 375 | } |
| 376 | |
| 377 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 8 | 12) { |
| 378 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 379 | "expected 8 or 12 bytes for TIME value, got {}", |
| 380 | buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 381 | ) |
| 382 | .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 383 | } |
| 384 | |
| 385 | let sign = MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::from_byterust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]from_byte().(buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 386 | // The wire protocol includes days but the text format doesn't. Isn't that crazy? |
| 387 | let days = buf.get_u32_lerust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u32_le().(); |
| 388 | let hours = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().(); |
| 389 | let minutes = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().(); |
| 390 | let seconds = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().(); |
| 391 | |
| 392 | let microseconds = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { buf.get_u32_lerust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u32_le().() } else { 0 }; |
| 393 | |
| 394 | let whole_hours = days |
| 395 | .checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]checked_mul().(24) |
| 396 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|days_to_hours| days_to_hours.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]checked_add().(hours as u32)) |
| 397 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("overflow calculating whole hours from `days * 24 + hours`")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 398 | |
| 399 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Decode<'r, MySql>`]::newrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]new().( |
| 400 | sign, |
| 401 | whole_hours, |
| 402 | minutes, |
| 403 | seconds, |
| 404 | microseconds, |
| 405 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 406 | } |
| 407 | MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#::Textrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Text# => parserust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse().(value.as_strrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]as_str().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | impl<'q> Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'q, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 413 | fn encode_by_refrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Encode<'q, MySql>`]encode_by_ref().( |
| 414 | &self, |
| 415 | buf: &mut <MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql# as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::ArgumentBufferrust-analyzer cargo sqlx-core 0.8.3 database/Database#ArgumentBuffer#<'q>, |
| 416 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 417 | if self.is_zerorust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]is_zero().() { |
| 418 | buf.put_u8rust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#put_u8().(0); |
| 419 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#::Norust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#No#); |
| 420 | } |
| 421 | |
| 422 | buf.put_u8rust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#put_u8().(self.encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]encoded_len().()); |
| 423 | buf.put_u8rust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#put_u8().(self.signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#sign..to_byterust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]to_byte().()); |
| 424 | |
| 425 | let TimeMagnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude# { |
| 426 | hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#hours.: whole_hours, |
| 427 | minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#minutes., |
| 428 | secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#seconds., |
| 429 | microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/TimeMagnitude#microseconds., |
| 430 | } = self.magnituderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#magnitude.; |
| 431 | |
| 432 | let days = whole_hours rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().24; |
| 433 | let hours = (whole_hours rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().24) as u8; |
| 434 | |
| 435 | buf.put_u32_lerust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#put_u32_le().(days); |
| 436 | buf.put_u8rust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#put_u8().(hours); |
| 437 | buf.put_u8rust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#put_u8().(minutes); |
| 438 | buf.put_u8rust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#put_u8().(seconds); |
| 439 | |
| 440 | if microseconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0 { |
| 441 | buf.put_u32_lerust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#put_u32_le().(microseconds); |
| 442 | } |
| 443 | |
| 444 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#::Norust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#No#) |
| 445 | } |
| 446 | |
| 447 | fn size_hintrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Encode<'q, MySql>`]size_hint().(&self) -> usize { |
| 448 | self.encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]encoded_len().() as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /// Convert [`MySqlTime`] from [`std::time::Duration`]. |
| 453 | /// |
| 454 | /// ### Note: Precision Truncation |
| 455 | /// [`Duration`] supports nanosecond precision, but MySQL `TIME` values only support microsecond |
| 456 | /// precision. |
| 457 | /// |
| 458 | /// For simplicity, higher precision values are truncated when converting. |
| 459 | /// If you prefer another rounding mode instead, you should apply that to the `Duration` first. |
| 460 | /// |
| 461 | /// See also: [MySQL Manual, section 13.2.6: Fractional Seconds in Time Values](https://dev.mysql.com/doc/refman/8.3/en/fractional-seconds.html) |
| 462 | /// |
| 463 | /// ### Errors: |
| 464 | /// Returns [`MySqlTimeError::FieldRange`] if the given duration is longer than `838:59:59.999999`. |
| 465 | /// |
| 466 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#> for MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 467 | type Errorrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`TryFrom<Duration>`]Error# = MySqlTimeErrorrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#; |
| 468 | |
| 469 | fn try_fromrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`TryFrom<Duration>`]try_from().(value: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`TryFrom<Duration>`], Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`TryFrom<Duration>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> { |
| 470 | let hours = value.as_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_secs().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().3600; |
| 471 | let rem_seconds = value.as_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_secs().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().3600; |
| 472 | let minutes = (rem_seconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().60) as u8; |
| 473 | let seconds = (rem_seconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().60) as u8; |
| 474 | |
| 475 | // Simply divides by 1000 |
| 476 | let microseconds = value.subsec_microsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]subsec_micros().(); |
| 477 | |
| 478 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`TryFrom<Duration>`]::newrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]new().( |
| 479 | MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive#, |
| 480 | hours.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| MySqlTimeErrorrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#::FieldRangerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#FieldRange# { |
| 481 | fieldrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#FieldRange#field.: "hours", |
| 482 | maxrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#FieldRange#max.: Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`TryFrom<Duration>`]::HOURS_MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]HOURS_MAX., |
| 483 | valuerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeError#FieldRange#value.: hours, |
| 484 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 485 | minutes, |
| 486 | seconds, |
| 487 | microseconds, |
| 488 | ) |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | impl MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign# { |
| 493 | fn from_byterust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]from_byte().(b: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 494 | match b { |
| 495 | 0 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive#), |
| 496 | 1 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative#), |
| 497 | other => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("expected 0 or 1 for TIME sign byte, got {other}").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | fn to_byterust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]to_byte().(self) -> u8 { |
| 502 | match self { |
| 503 | // We can't use `#[repr(u8)]` because this is opposite of the ordering we want from `Ord` |
| 504 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative# => 1, |
| 505 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive# => 0, |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | fn signumrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]signum().(&self) -> i32 { |
| 510 | match self { |
| 511 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative# => -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1, |
| 512 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive# => 1, |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | /// Returns `true` if positive, `false` if negative. |
| 517 | pub fn is_positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]is_positive().(&self) -> bool { |
| 518 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive#) |
| 519 | } |
| 520 | |
| 521 | /// Returns `true` if negative, `false` if positive. |
| 522 | pub fn is_negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]is_negative().(&self) -> bool { |
| 523 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign]::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative#) |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign# { |
| 528 | fn fmtrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign][Display]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 529 | match self { |
| 530 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign][Display]::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive# if f.sign_plusrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]sign_plus().() => f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('+'), |
| 531 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTimeSign][Display]::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative# => f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('-'), |
| 532 | _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration# { |
| 538 | fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[Duration][`Type<MySql>`]type_info().() -> MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo# { |
| 539 | MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Type<MySql>`]type_info().() |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration# { |
| 544 | fn decoderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[Duration][`Decode<'r, MySql>`]decode().(value: <MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql# as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::ValueRefrust-analyzer cargo sqlx-core 0.8.3 database/Database#ValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[Duration][`Decode<'r, MySql>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 545 | let time = MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::decoderust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`Decode<'r, MySql>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 546 | |
| 547 | time.to_durationrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]to_duration().().ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| { |
| 548 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("`std::time::Duration` can only decode positive TIME values; got {time}").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 549 | }) |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | // Not exposing this as a `FromStr` impl currently because `MySqlTime` is not designed to be |
| 554 | // a general interchange type. |
| 555 | fn parserust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse().(text: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 556 | let mut segments = text.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(':'); |
| 557 | |
| 558 | let hours = segments |
| 559 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() |
| 560 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("expected hours segment, got nothing")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 561 | |
| 562 | let minutes = segments |
| 563 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() |
| 564 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("expected minutes segment, got nothing")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 565 | |
| 566 | let seconds = segments |
| 567 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() |
| 568 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("expected seconds segment, got nothing")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 569 | |
| 570 | // Include the sign in parsing for convenience; |
| 571 | // the allowed range of whole hours is much smaller than `i32`'s positive range. |
| 572 | let hours: i32 = hours |
| 573 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 574 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("error parsing hours from {text:?} (segment {hours:?}): {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 575 | |
| 576 | let sign = if hours.is_negativerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]is_negative().() { |
| 577 | MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative# |
| 578 | } else { |
| 579 | MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive# |
| 580 | }; |
| 581 | |
| 582 | let hours = hours.unsigned_absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]unsigned_abs().(); |
| 583 | |
| 584 | let minutes: u8 = minutes |
| 585 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 586 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("error parsing minutes from {text:?} (segment {minutes:?}): {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 587 | |
| 588 | let (seconds, microseconds): (u8, u32) = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((seconds, microseconds)) = |
| 589 | seconds.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('.') |
| 590 | { |
| 591 | ( |
| 592 | seconds.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| { |
| 593 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("error parsing seconds from {text:?} (segment {seconds:?}): {e}") |
| 594 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 595 | parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse_microseconds().(microseconds).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| { |
| 596 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("error parsing microseconds from {text:?} (segment {microseconds:?}): {e}") |
| 597 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 598 | ) |
| 599 | } else { |
| 600 | ( |
| 601 | seconds.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| { |
| 602 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("error parsing seconds from {text:?} (segment {seconds:?}): {e}") |
| 603 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 604 | 0, |
| 605 | ) |
| 606 | }; |
| 607 | |
| 608 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::newrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]new().(sign, hours, minutes, seconds, microseconds)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 609 | } |
| 610 | |
| 611 | /// Parse microseconds from a fractional seconds string. |
| 612 | fn parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse_microseconds().(micros: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u32, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 613 | const EXPECTED_DIGITSrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/EXPECTED_DIGITS.: usize = 6; |
| 614 | |
| 615 | match micros.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() { |
| 616 | 0 => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("empty string".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 617 | len @ ..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeToInclusive#EXPECTED_DIGITSrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/EXPECTED_DIGITS. => { |
| 618 | // Fewer than 6 digits, multiply to the correct magnitude |
| 619 | let micros: u32 = micros.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 620 | // cast cannot overflow |
| 621 | #[allow(clippy::cast_possible_truncation)] |
| 622 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(micros rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().10u32.powrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]pow().((EXPECTED_DIGITSrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/EXPECTED_DIGITS. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().len) as u32)) |
| 623 | } |
| 624 | // More digits than expected, truncate |
| 625 | _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(micros[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#EXPECTED_DIGITSrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/EXPECTED_DIGITS.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | #[cfg(test)] |
| 630 | mod testsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/tests/ { |
| 631 | use superrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/::MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#; |
| 632 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::typesrust-analyzer cargo sqlx-mysql 0.8.3 types/::MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#; |
| 633 | |
| 634 | use superrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/::parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse_microseconds().; |
| 635 | |
| 636 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 637 | fn test_displayrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/tests/test_display().() { |
| 638 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]ZERO..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "0:00:00"); |
| 639 | |
| 640 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.0}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]ZERO.), "0:00:00"); |
| 641 | |
| 642 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.3}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]ZERO.), "0:00:00.000"); |
| 643 | |
| 644 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.6}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]ZERO.), "0:00:00.000000"); |
| 645 | |
| 646 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.9}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::ZEROrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]ZERO.), "0:00:00.000000000"); |
| 647 | |
| 648 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.0}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.), "838:59:59"); |
| 649 | |
| 650 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.3}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.), "838:59:59.000"); |
| 651 | |
| 652 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.6}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.), "838:59:59.000000"); |
| 653 | |
| 654 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.9}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.), "838:59:59.000000000"); |
| 655 | |
| 656 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:+.0}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.), "+838:59:59"); |
| 657 | |
| 658 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:+.3}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.), "+838:59:59.000"); |
| 659 | |
| 660 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:+.6}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.), "+838:59:59.000000"); |
| 661 | |
| 662 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:+.9}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MAXrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MAX.), "+838:59:59.000000000"); |
| 663 | |
| 664 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.0}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MINrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MIN.), "-838:59:59"); |
| 665 | |
| 666 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.3}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MINrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MIN.), "-838:59:59.000"); |
| 667 | |
| 668 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.6}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MINrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MIN.), "-838:59:59.000000"); |
| 669 | |
| 670 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.9}", MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::MINrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]MIN.), "-838:59:59.000000000"); |
| 671 | |
| 672 | let positive = MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::newrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]new().(MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Positiverust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Positive#, 123, 45, 56, 890011).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 673 | |
| 674 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(positive.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "123:45:56.890011"); |
| 675 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{positive:.0}"), "123:45:56"); |
| 676 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{positive:.3}"), "123:45:56.890"); |
| 677 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{positive:.6}"), "123:45:56.890011"); |
| 678 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{positive:.9}"), "123:45:56.890011000"); |
| 679 | |
| 680 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{positive:+.0}"), "+123:45:56"); |
| 681 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{positive:+.3}"), "+123:45:56.890"); |
| 682 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{positive:+.6}"), "+123:45:56.890011"); |
| 683 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{positive:+.9}"), "+123:45:56.890011000"); |
| 684 | |
| 685 | let negative = MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#::newrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]new().(MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#::Negativerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#Negative#, 123, 45, 56, 890011).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 686 | |
| 687 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(negative.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "-123:45:56.890011"); |
| 688 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{negative:.0}"), "-123:45:56"); |
| 689 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{negative:.3}"), "-123:45:56.890"); |
| 690 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{negative:.6}"), "-123:45:56.890011"); |
| 691 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{negative:.9}"), "-123:45:56.890011000"); |
| 692 | } |
| 693 | |
| 694 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 695 | fn test_parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/tests/test_parse_microseconds().() { |
| 696 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse_microseconds().("010").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 10_000); |
| 697 | |
| 698 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse_microseconds().("0100000000").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 10_000); |
| 699 | |
| 700 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse_microseconds().("890").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 890_000); |
| 701 | |
| 702 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse_microseconds().("0890").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 89_000); |
| 703 | |
| 704 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 705 | // Case in point about not exposing this: |
| 706 | // we always truncate excess precision because it's simpler than rounding |
| 707 | // and MySQL should never return a higher precision. |
| 708 | parse_microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/parse_microseconds().("123456789").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 709 | 123456, |
| 710 | ); |
| 711 | } |
| 712 | } |