| 1 | use byteorderrust-analyzer cargo byteorder 1.5.0 crate/::{ByteOrderrust-analyzer cargo byteorder 1.5.0 ByteOrder#, LittleEndianrust-analyzer cargo byteorder 1.5.0 LittleEndian#}; |
| 2 | use bytesrust-analyzer cargo bytes 1.12.1 crate/::Bufrust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#; |
| 3 | 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#; |
| 4 | use timerust-analyzer cargo time 0.3.55 crate/::macrosrust-analyzer cargo time 0.3.55 macros/::format_descriptionrust-analyzer cargo time-macros 0.2.32 format_description!; |
| 5 | use timerust-analyzer cargo time 0.3.55 crate/::{Daterust-analyzer cargo time 0.3.55 date/Date#, OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime#, PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#, Timerust-analyzer cargo time 0.3.55 time/Time#, UtcOffsetrust-analyzer cargo time 0.3.55 utc_offset/UtcOffset#}; |
| 6 | |
| 7 | use craterust-analyzer cargo sqlx-mysql 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 craterust-analyzer cargo sqlx-mysql 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 craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::errorrust-analyzer cargo sqlx-mysql 0.8.3 error/::{BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#, UnexpectedNullErrorrust-analyzer cargo sqlx-core 0.8.3 error/UnexpectedNullError#}; |
| 10 | 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#; |
| 11 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::type_inforust-analyzer cargo sqlx-mysql 0.8.3 type_info/::MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#; |
| 12 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::typesrust-analyzer cargo sqlx-mysql 0.8.3 types/::{MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#, MySqlTimeSignrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTimeSign#, Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#}; |
| 13 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::{MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#, MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#, MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#}; |
| 14 | |
| 15 | impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime# { |
| 16 | fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[OffsetDateTime][`Type<MySql>`]type_info().() -> MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo# { |
| 17 | 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#::Timestamprust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Timestamp#) |
| 18 | } |
| 19 | |
| 20 | fn compatiblerust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[OffsetDateTime][`Type<MySql>`]compatible().(ty: &MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#) -> bool { |
| 21 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(ty.r#typerust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#`r#type`., ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Datetimerust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Datetime# | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Timestamprust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Timestamp#) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime# { |
| 26 | fn encode_by_refrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[OffsetDateTime][`Encode<'_, MySql>`]encode_by_ref().(&self, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> 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#> { |
| 27 | let utc_dt = self.to_offsetrust-analyzer cargo time 0.3.55 offset_date_time/impl#[OffsetDateTime]to_offset().(UtcOffsetrust-analyzer cargo time 0.3.55 utc_offset/UtcOffset#::UTCrust-analyzer cargo time 0.3.55 utc_offset/impl#[UtcOffset]UTC.); |
| 28 | let primitive_dt = PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#::newrust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]new().(utc_dt.daterust-analyzer cargo time 0.3.55 offset_date_time/impl#[OffsetDateTime]date().(), utc_dt.timerust-analyzer cargo time 0.3.55 offset_date_time/impl#[OffsetDateTime]time().()); |
| 29 | |
| 30 | Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#encode().(primitive_dt, buf) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime# { |
| 35 | fn decoderust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[OffsetDateTime][`Decode<'r, MySql>`]decode().(value: MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[OffsetDateTime][`Decode<'r, MySql>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 36 | let primitive: PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# = Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#::<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#>::decoderust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::PlainDateTime`][`Decode<'r, MySql>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 37 | |
| 38 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(primitive.assume_utcrust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]assume_utc().()) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Timerust-analyzer cargo time 0.3.55 time/Time# { |
| 43 | fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`Type<MySql>`]type_info().() -> MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo# { |
| 44 | 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#) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Timerust-analyzer cargo time 0.3.55 time/Time# { |
| 49 | fn encode_by_refrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`Encode<'_, MySql>`]encode_by_ref().(&self, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> 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#> { |
| 50 | let len = time_encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/time/time_encoded_len().(self); |
| 51 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(len); |
| 52 | |
| 53 | // sign byte: Time is never negative |
| 54 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0); |
| 55 | |
| 56 | // Number of days in the interval; always 0 for time-of-day values. |
| 57 | // https://mariadb.com/kb/en/resultset-row/#teimstamp-binary-encoding |
| 58 | buf.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&[0_u8; 4]); |
| 59 | |
| 60 | encode_timerust-analyzer cargo sqlx-mysql 0.8.3 types/time/encode_time().(self, len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().8, buf); |
| 61 | |
| 62 | 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#) |
| 63 | } |
| 64 | |
| 65 | fn size_hintrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`Encode<'_, MySql>`]size_hint().(&self) -> usize { |
| 66 | time_encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/time/time_encoded_len().(self) 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 // plus length byte |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Timerust-analyzer cargo time 0.3.55 time/Time# { |
| 71 | fn decoderust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`Decode<'r, MySql>`]decode().(value: MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`Decode<'r, MySql>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 72 | match value.formatrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]format().() { |
| 73 | MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#::Binaryrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Binary# => { |
| 74 | // Should never panic. |
| 75 | 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()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() |
| 76 | } |
| 77 | |
| 78 | // Retaining this parsing for now as it allows us to cross-check our impl. |
| 79 | MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#::Textrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Text# => Timerust-analyzer cargo time 0.3.55 time/Time#::parserust-analyzer cargo time 0.3.55 time/impl#[Time]parse().( |
| 80 | 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()., |
| 81 | &format_descriptionrust-analyzer cargo time-macros 0.2.32 format_description!!("[hour]:[minute]:[second].[subsecond]"), |
| 82 | ) |
| 83 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().), |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#> for Timerust-analyzer cargo time 0.3.55 time/Time# { |
| 89 | type Errorrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`TryFrom<MySqlTime>`]Error# = BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#; |
| 90 | |
| 91 | fn try_fromrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`TryFrom<MySqlTime>`]try_from().(time: MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`TryFrom<MySqlTime>`], Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Time][`TryFrom<MySqlTime>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> { |
| 92 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().time.is_valid_time_of_dayrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]is_valid_time_of_day().() { |
| 93 | 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!!("MySqlTime value out of range for `time::Time`: {time}").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 94 | } |
| 95 | |
| 96 | #[allow(clippy::cast_possible_truncation)] |
| 97 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Timerust-analyzer cargo time 0.3.55 time/Time#::from_hms_microrust-analyzer cargo time 0.3.55 time/impl#[Time]from_hms_micro().( |
| 98 | // `is_valid_time_of_day()` ensures this won't overflow |
| 99 | time.hoursrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]hours().() as u8, |
| 100 | time.minutesrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]minutes().(), |
| 101 | time.secondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]seconds().(), |
| 102 | time.microsecondsrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]microseconds().(), |
| 103 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#> for timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration# { |
| 108 | fn fromrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::SignedDuration`][`From<MySqlTime>`]from().(time: MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime#) -> Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::SignedDuration`][`From<MySqlTime>`] { |
| 109 | // `subsec_nanos()` is guaranteed to be between 0 and 10^9 |
| 110 | #[allow(clippy::cast_possible_wrap)] |
| 111 | timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#::newrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]new().(time.whole_seconds_signedrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]whole_seconds_signed().(), time.subsec_nanosrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]subsec_nanos().() as i32) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#> for MySqlTimerust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/MySqlTime# { |
| 116 | type Errorrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[MySqlTime][`TryFrom<time::SignedDuration>`]Error# = BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#; |
| 117 | |
| 118 | fn try_fromrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[MySqlTime][`TryFrom<time::SignedDuration>`]try_from().(value: timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[MySqlTime][`TryFrom<time::SignedDuration>`], Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[MySqlTime][`TryFrom<time::SignedDuration>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> { |
| 119 | let sign = if value.is_negativerust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]is_negative().() { |
| 120 | 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# |
| 121 | } else { |
| 122 | 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 | }; |
| 124 | |
| 125 | // Similar to `TryFrom<chrono::TimeDelta>`, use `std::time::Duration` as an intermediate. |
| 126 | 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#::try_fromrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime][`TryFrom<Duration>`]try_from().(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#::try_fromrust-analyzer cargo time 0.3.55 signed_duration/impl#[StdDuration][`TryFrom<SignedDuration>`]try_from().(value.absrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]abs().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..with_signrust-analyzer cargo sqlx-mysql 0.8.3 types/mysql_time/impl#[MySqlTime]with_sign().(sign)) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration# { |
| 131 | fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::SignedDuration`][`Type<MySql>`]type_info().() -> MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo# { |
| 132 | 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().() |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration# { |
| 137 | fn decoderust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::SignedDuration`][`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/time/impl#[`time::SignedDuration`][`Decode<'r, MySql>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 138 | 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#::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()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Daterust-analyzer cargo time 0.3.55 date/Date# { |
| 143 | fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Date][`Type<MySql>`]type_info().() -> MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo# { |
| 144 | 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#::Daterust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Date#) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Daterust-analyzer cargo time 0.3.55 date/Date# { |
| 149 | fn encode_by_refrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Date][`Encode<'_, MySql>`]encode_by_ref().(&self, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> 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#> { |
| 150 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(4); |
| 151 | |
| 152 | encode_daterust-analyzer cargo sqlx-mysql 0.8.3 types/time/encode_date().(self, buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 153 | |
| 154 | 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#) |
| 155 | } |
| 156 | |
| 157 | fn size_hintrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Date][`Encode<'_, MySql>`]size_hint().(&self) -> usize { |
| 158 | 5 |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Daterust-analyzer cargo time 0.3.55 date/Date# { |
| 163 | fn decoderust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Date][`Decode<'r, MySql>`]decode().(value: MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[Date][`Decode<'r, MySql>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 164 | match value.formatrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]format().() { |
| 165 | MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#::Binaryrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Binary# => { |
| 166 | let 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().; |
| 167 | |
| 168 | // Row decoding should leave the length byte on the front. |
| 169 | if buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 170 | 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().()); |
| 171 | } |
| 172 | |
| 173 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decode_daterust-analyzer cargo sqlx-mysql 0.8.3 types/time/decode_date().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]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 result/impl#[`Result<T, E>`][Try]branch()..ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(UnexpectedNullErrorrust-analyzer cargo sqlx-core 0.8.3 error/UnexpectedNullError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 174 | } |
| 175 | MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#::Textrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Text# => { |
| 176 | let s = 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().; |
| 177 | Daterust-analyzer cargo time 0.3.55 date/Date#::parserust-analyzer cargo time 0.3.55 date/impl#[Date]parse().(s, &format_descriptionrust-analyzer cargo time-macros 0.2.32 format_description!!("[year]-[month]-[day]")).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().) |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# { |
| 184 | fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::PlainDateTime`][`Type<MySql>`]type_info().() -> MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo# { |
| 185 | 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#::Datetimerust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Datetime#) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# { |
| 190 | fn encode_by_refrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::PlainDateTime`][`Encode<'_, MySql>`]encode_by_ref().(&self, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> 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#> { |
| 191 | let len = primitive_dt_encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/time/primitive_dt_encoded_len().(self); |
| 192 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(len); |
| 193 | |
| 194 | encode_daterust-analyzer cargo sqlx-mysql 0.8.3 types/time/encode_date().(&self.daterust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]date().(), buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 195 | |
| 196 | if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().4 { |
| 197 | encode_timerust-analyzer cargo sqlx-mysql 0.8.3 types/time/encode_time().(&self.timerust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]time().(), len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().7, buf); |
| 198 | } |
| 199 | |
| 200 | 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#) |
| 201 | } |
| 202 | |
| 203 | fn size_hintrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::PlainDateTime`][`Encode<'_, MySql>`]size_hint().(&self) -> usize { |
| 204 | primitive_dt_encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/time/primitive_dt_encoded_len().(self) 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 // plus length byte |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# { |
| 209 | fn decoderust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::PlainDateTime`][`Decode<'r, MySql>`]decode().(value: MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/time/impl#[`time::PlainDateTime`][`Decode<'r, MySql>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 210 | match value.formatrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]format().() { |
| 211 | MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#::Binaryrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Binary# => { |
| 212 | 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().; |
| 213 | |
| 214 | if buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 215 | 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().()); |
| 216 | } |
| 217 | |
| 218 | let len = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().(); |
| 219 | |
| 220 | let date = decode_daterust-analyzer cargo sqlx-mysql 0.8.3 types/time/decode_date().(buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(UnexpectedNullErrorrust-analyzer cargo sqlx-core 0.8.3 error/UnexpectedNullError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 221 | |
| 222 | let dt = if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().4 { |
| 223 | date.with_timerust-analyzer cargo time 0.3.55 date/impl#[Date]with_time().(decode_timerust-analyzer cargo sqlx-mysql 0.8.3 types/time/decode_time().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]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 result/impl#[`Result<T, E>`][Try]branch().) |
| 224 | } else { |
| 225 | date.midnightrust-analyzer cargo time 0.3.55 date/impl#[Date]midnight().() |
| 226 | }; |
| 227 | |
| 228 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(dt) |
| 229 | } |
| 230 | |
| 231 | MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#::Textrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Text# => { |
| 232 | let s = 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().; |
| 233 | |
| 234 | // If there are no nanoseconds parse without them |
| 235 | if s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('.') { |
| 236 | PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#::parserust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]parse().( |
| 237 | s, |
| 238 | &format_descriptionrust-analyzer cargo time-macros 0.2.32 format_description!!( |
| 239 | "[year]-[month]-[day] [hour]:[minute]:[second].[subsecond]" |
| 240 | ), |
| 241 | ) |
| 242 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().) |
| 243 | } else { |
| 244 | PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#::parserust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]parse().( |
| 245 | s, |
| 246 | &format_descriptionrust-analyzer cargo time-macros 0.2.32 format_description!!("[year]-[month]-[day] [hour]:[minute]:[second]"), |
| 247 | ) |
| 248 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().) |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | fn encode_daterust-analyzer cargo sqlx-mysql 0.8.3 types/time/encode_date().(date: &Daterust-analyzer cargo time 0.3.55 date/Date#, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 256 | // MySQL supports years from 1000 - 9999 |
| 257 | let year = |
| 258 | u16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u16][`TryFrom<i32>`]try_from().(date.yearrust-analyzer cargo time 0.3.55 date/impl#[Date]year().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Date out of range for Mysql: {date}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 259 | |
| 260 | buf.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&year.to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_le_bytes().()); |
| 261 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(date.monthrust-analyzer cargo time 0.3.55 date/impl#[Date]month().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 262 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(date.dayrust-analyzer cargo time 0.3.55 date/impl#[Date]day().()); |
| 263 | |
| 264 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 265 | } |
| 266 | |
| 267 | fn decode_daterust-analyzer cargo sqlx-mysql 0.8.3 types/time/decode_date().(buf: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Daterust-analyzer cargo time 0.3.55 date/Date#>, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 268 | if buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 269 | // zero buffer means a zero date (null) |
| 270 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 271 | } |
| 272 | |
| 273 | Daterust-analyzer cargo time 0.3.55 date/Date#::from_calendar_daterust-analyzer cargo time 0.3.55 date/impl#[Date]from_calendar_date().( |
| 274 | LittleEndianrust-analyzer cargo byteorder 1.5.0 LittleEndian#::read_u16rust-analyzer cargo byteorder 1.5.0 impl#[LittleEndian][ByteOrder]read_u16().(buf) as i32, |
| 275 | timerust-analyzer cargo time 0.3.55 crate/::Monthrust-analyzer cargo time 0.3.55 month/Month#::try_fromrust-analyzer cargo time 0.3.55 month/impl#[Month][`TryFrom<u8>`]try_from().(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2]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 result/impl#[`Result<T, E>`][Try]branch()., |
| 276 | buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 277 | ) |
| 278 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().) |
| 279 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#) |
| 280 | } |
| 281 | |
| 282 | fn encode_timerust-analyzer cargo sqlx-mysql 0.8.3 types/time/encode_time().(time: &Timerust-analyzer cargo time 0.3.55 time/Time#, include_micros: bool, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) { |
| 283 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(time.hourrust-analyzer cargo time 0.3.55 time/impl#[Time]hour().()); |
| 284 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(time.minuterust-analyzer cargo time 0.3.55 time/impl#[Time]minute().()); |
| 285 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(time.secondrust-analyzer cargo time 0.3.55 time/impl#[Time]second().()); |
| 286 | |
| 287 | if include_micros { |
| 288 | buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&(time.nanosecondrust-analyzer cargo time 0.3.55 time/impl#[Time]nanosecond().() 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().1000).to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_le_bytes().()); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | fn decode_timerust-analyzer cargo sqlx-mysql 0.8.3 types/time/decode_time().(mut buf: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Timerust-analyzer cargo time 0.3.55 time/Time#, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 293 | let hour = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().(); |
| 294 | let minute = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().(); |
| 295 | let seconds = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().(); |
| 296 | |
| 297 | let micros = 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().() { |
| 298 | // microseconds : int<EOF> |
| 299 | buf.get_uint_lerust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_uint_le().(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 300 | } else { |
| 301 | 0 |
| 302 | }; |
| 303 | |
| 304 | let micros = u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`TryFrom<u64>`]try_from().(micros) |
| 305 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("MySQL returned microseconds out of range: {micros}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 306 | |
| 307 | Timerust-analyzer cargo time 0.3.55 time/Time#::from_hms_microrust-analyzer cargo time 0.3.55 time/impl#[Time]from_hms_micro().(hour, minute, seconds, micros) |
| 308 | .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!!("Time out of range for MySQL: {e}").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 309 | } |
| 310 | |
| 311 | #[inline(always)] |
| 312 | fn primitive_dt_encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/time/primitive_dt_encoded_len().(time: &PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#) -> u8 { |
| 313 | // to save space the packet can be compressed: |
| 314 | match (time.hourrust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]hour().(), time.minuterust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]minute().(), time.secondrust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]second().(), time.nanosecondrust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]nanosecond().()) { |
| 315 | // if hour, minutes, seconds and micro_seconds are all 0, |
| 316 | // length is 4 and no other field is sent |
| 317 | (0, 0, 0, 0) => 4, |
| 318 | |
| 319 | // if micro_seconds is 0, length is 7 |
| 320 | // and micro_seconds is not sent |
| 321 | (_, _, _, 0) => 7, |
| 322 | |
| 323 | // otherwise length is 11 |
| 324 | (_, _, _, _) => 11, |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | #[inline(always)] |
| 329 | fn time_encoded_lenrust-analyzer cargo sqlx-mysql 0.8.3 types/time/time_encoded_len().(time: &Timerust-analyzer cargo time 0.3.55 time/Time#) -> u8 { |
| 330 | if time.nanosecondrust-analyzer cargo time 0.3.55 time/impl#[Time]nanosecond().() 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 { |
| 331 | // if micro_seconds is 0, length is 8 and micro_seconds is not sent |
| 332 | 8 |
| 333 | } else { |
| 334 | // otherwise length is 12 |
| 335 | 12 |
| 336 | } |
| 337 | } |