Debian Codegraph @

src/types/interval.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/;
2
3 use byteorderrust-analyzer cargo byteorder 1.5.0 crate/::{NetworkEndianrust-analyzer cargo byteorder 1.5.0 NetworkEndian#, ReadBytesExtrust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#};
4
5 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::decoderust-analyzer cargo sqlx-core 0.8.3 decode/::Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#;
6 use craterust-analyzer cargo sqlx-postgres 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#};
7 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#;
8 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::typesrust-analyzer cargo sqlx-postgres 0.8.3 types/::Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#;
9 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::{PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#, PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType#, PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#, PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#, PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#};
10
11 // `PgInterval` is available for direct access to the INTERVAL type
12
13 #[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:, 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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
14 pub struct PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
15 pub monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: i32,
16 pub daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: i32,
17 pub microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: i64,
18 }
19
20 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
21 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
22 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::INTERVALrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]INTERVAL.
23 }
24 }
25
26 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
27 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
28 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::INTERVAL_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]INTERVAL_ARRAY.
29 }
30 }
31
32 impl<'de> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'de, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
33 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`Decode<'de, Postgres>`]decode().(value: PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'de>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`Decode<'de, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
34 match value.formatrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]format().() {
35 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Binaryrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Binary# => {
36 let mut buf = value.as_bytesrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]as_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
37 let microseconds = buf.read_i64rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_i64().::<NetworkEndianrust-analyzer cargo byteorder 1.5.0 NetworkEndian#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
38 let days = buf.read_i32rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_i32().::<NetworkEndianrust-analyzer cargo byteorder 1.5.0 NetworkEndian#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
39 let months = buf.read_i32rust-analyzer cargo byteorder 1.5.0 io/ReadBytesExt#read_i32().::<NetworkEndianrust-analyzer cargo byteorder 1.5.0 NetworkEndian#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
40
41 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
42 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.,
43 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.,
44 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.,
45 })
46 }
47
48 // TODO: Implement parsing of text mode
49 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Textrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Text# => {
50 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("not implemented: decode `INTERVAL` in text mode (unprepared queries)".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
51 }
52 }
53 }
54 }
55
56 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
57 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`Encode<'_, Postgres>`]encode_by_ref().(&self, buf: &mut PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#) -> 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#> {
58 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&self.microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds..to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]to_be_bytes().());
59 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&self.daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days..to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]to_be_bytes().());
60 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&self.monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months..to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]to_be_bytes().());
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-postgres 0.8.3 types/interval/impl#[PgInterval][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
66 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<i64>()
67 }
68 }
69
70 // We then implement Encode + Type for std Duration, chrono Duration, and time Duration
71 // This is to enable ease-of-use for encoding when its simple
72
73 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for 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# {
74 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`std::time::Duration`][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
75 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::INTERVALrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]INTERVAL.
76 }
77 }
78
79 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for 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# {
80 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`std::time::Duration`][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
81 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::INTERVAL_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]INTERVAL_ARRAY.
82 }
83 }
84
85 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for 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# {
86 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`std::time::Duration`][`Encode<'_, Postgres>`]encode_by_ref().(&self, buf: &mut PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#) -> 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#> {
87 PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<std::time::Duration>`]try_from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`Encode<'_, Postgres>`]encode_by_ref().(buf)
88 }
89
90 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`std::time::Duration`][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
91 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<i64>()
92 }
93 }
94
95 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<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#> for PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
96 type Errorrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<std::time::Duration>`]Error# = BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#;
97
98 /// Convert a `std::time::Duration` to a `PgInterval`
99 ///
100 /// This returns an error if there is a loss of precision using nanoseconds or if there is a
101 /// microsecond overflow.
102 fn try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<std::time::Duration>`]try_from().(value: 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#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<std::time::Duration>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
103 if value.as_nanosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_nanos().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`Rem<Self>`]rem().1000 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]ne().0 {
104 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("PostgreSQL `INTERVAL` does not support nanoseconds precision".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
105 }
106
107 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<std::time::Duration>`] {
108 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
109 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
110 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: value.as_microsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_micros().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
111 })
112 }
113 }
114
115 #[cfg(feature = "chrono")]
116 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration# {
117 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`chrono::TimeDelta`][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
118 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::INTERVALrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]INTERVAL.
119 }
120 }
121
122 #[cfg(feature = "chrono")]
123 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration# {
124 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`chrono::TimeDelta`][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
125 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::INTERVAL_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]INTERVAL_ARRAY.
126 }
127 }
128
129 #[cfg(feature = "chrono")]
130 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration# {
131 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`chrono::TimeDelta`][`Encode<'_, Postgres>`]encode_by_ref().(&self, buf: &mut PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#) -> 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#> {
132 let pg_interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]try_from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
133 pg_interval.encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`Encode<'_, Postgres>`]encode_by_ref().(buf)
134 }
135
136 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`chrono::TimeDelta`][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
137 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<i64>()
138 }
139 }
140
141 #[cfg(feature = "chrono")]
142 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration#> for PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
143 type Errorrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]Error# = BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#;
144
145 /// Convert a `chrono::Duration` to a `PgInterval`.
146 ///
147 /// This returns an error if there is a loss of precision using nanoseconds or if there is a
148 /// nanosecond overflow.
149 fn try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]try_from().(value: chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
150 value
151 .num_nanosecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]num_nanoseconds().()
152 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<_, Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#>, _>(
153 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Overflow has occurred for PostgreSQL `INTERVAL`".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
154 |nanoseconds| {
155 if nanoseconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem().1000 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().0 {
156 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(
157 "PostgreSQL `INTERVAL` does not support nanoseconds precision".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
158 );
159 }
160 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
161 },
162 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
163
164 value.num_microsecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]num_microseconds().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(
165 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Overflow has occurred for PostgreSQL `INTERVAL`".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
166 |microseconds| {
167 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`] {
168 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
169 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
170 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.,
171 })
172 },
173 )
174 }
175 }
176
177 #[cfg(feature = "time")]
178 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration# {
179 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`time::SignedDuration`][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
180 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::INTERVALrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]INTERVAL.
181 }
182 }
183
184 #[cfg(feature = "time")]
185 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration# {
186 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`time::SignedDuration`][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
187 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::INTERVAL_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]INTERVAL_ARRAY.
188 }
189 }
190
191 #[cfg(feature = "time")]
192 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration# {
193 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`time::SignedDuration`][`Encode<'_, Postgres>`]encode_by_ref().(&self, buf: &mut PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#) -> 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#> {
194 let pg_interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`]try_from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
195 pg_interval.encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`Encode<'_, Postgres>`]encode_by_ref().(buf)
196 }
197
198 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[`time::SignedDuration`][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
199 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<i64>()
200 }
201 }
202
203 #[cfg(feature = "time")]
204 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 PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
205 type Errorrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`]Error# = BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#;
206
207 /// Convert a `time::Duration` to a `PgInterval`.
208 ///
209 /// This returns an error if there is a loss of precision using nanoseconds or if there is a
210 /// microsecond overflow.
211 fn try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`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-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
212 if value.whole_nanosecondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]whole_nanoseconds().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i128][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i128][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i128][`Rem<Self>`]rem().1000 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialEq<Self>`]ne().0 {
213 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("PostgreSQL `INTERVAL` does not support nanoseconds precision".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
214 }
215
216 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`] {
217 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
218 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
219 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: value.whole_microsecondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]whole_microseconds().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
220 })
221 }
222 }
223
224 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
225 fn test_encode_intervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/test_encode_interval().() {
226 let mut buf = PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#::defaultrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Default]default().();
227
228 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
229 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
230 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
231 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 0,
232 };
233 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
234 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/impl#[`&T`][`Encode<'q, DB>`]encode().(&interval, &mut buf),
235 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#)
236 ));
237 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().*rust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]deref().buf, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
238 buf.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
239
240 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
241 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
242 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
243 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 1_000,
244 };
245 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
246 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/impl#[`&T`][`Encode<'q, DB>`]encode().(&interval, &mut buf),
247 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#)
248 ));
249 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().*rust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]deref().buf, [0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 0, 0, 0, 0, 0, 0]);
250 buf.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
251
252 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
253 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
254 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
255 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 1_000_000,
256 };
257 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
258 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/impl#[`&T`][`Encode<'q, DB>`]encode().(&interval, &mut buf),
259 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#)
260 ));
261 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().*rust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]deref().buf, [0, 0, 0, 0, 0, 15, 66, 64, 0, 0, 0, 0, 0, 0, 0, 0]);
262 buf.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
263
264 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
265 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
266 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
267 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 3_600_000_000,
268 };
269 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
270 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/impl#[`&T`][`Encode<'q, DB>`]encode().(&interval, &mut buf),
271 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#)
272 ));
273 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
274 &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().*rust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]deref().buf,
275 [0, 0, 0, 0, 214, 147, 164, 0, 0, 0, 0, 0, 0, 0, 0, 0]
276 );
277 buf.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
278
279 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
280 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
281 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 1,
282 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 0,
283 };
284 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
285 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/impl#[`&T`][`Encode<'q, DB>`]encode().(&interval, &mut buf),
286 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#)
287 ));
288 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().*rust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]deref().buf, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]);
289 buf.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
290
291 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
292 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 1,
293 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
294 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 0,
295 };
296 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
297 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/impl#[`&T`][`Encode<'q, DB>`]encode().(&interval, &mut buf),
298 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#)
299 ));
300 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().*rust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]deref().buf, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
301 buf.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
302
303 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
304 PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::defaultrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][Default]default().(),
305 PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
306 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
307 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
308 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 0,
309 }
310 );
311 }
312
313 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
314 fn test_pginterval_stdrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/test_pginterval_std().() {
315 // Case for positive duration
316 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
317 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
318 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
319 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 27_000,
320 };
321 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
322 &PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<std::time::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#::from_microsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_micros().(27_000)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
323 &interval
324 );
325
326 // Case when precision loss occurs
327 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<std::time::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#::from_nanosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_nanos().(27_000_001)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
328
329 // Case when microsecond overflow occurs
330 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<std::time::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#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(20_000_000_000_000)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
331 }
332
333 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
334 #[cfg(feature = "chrono")]
335 fn test_pginterval_chronorust-analyzer cargo sqlx-postgres 0.8.3 types/interval/test_pginterval_chrono().() {
336 // Case for positive duration
337 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
338 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
339 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
340 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 27_000,
341 };
342 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
343 &PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]try_from().(chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration#::microsecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]microseconds().(27_000)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
344 &interval
345 );
346
347 // Case for negative duration
348 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
349 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
350 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
351 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().27_000,
352 };
353 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
354 &PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]try_from().(chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration#::microsecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]microseconds().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().27_000)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
355 &interval
356 );
357
358 // Case when precision loss occurs
359 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]try_from().(chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration#::nanosecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]nanoseconds().(27_000_001)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
360 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]try_from().(chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration#::nanosecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]nanoseconds().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().27_000_001)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
361
362 // Case when nanosecond overflow occurs
363 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]try_from().(chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration#::secondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]seconds().(10_000_000_000)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
364 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<chrono::TimeDelta>`]try_from().(chronorust-analyzer cargo chrono 0.4.45 crate/::Durationrust-analyzer cargo chrono 0.4.45 Duration#::secondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]seconds().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().10_000_000_000)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
365 }
366
367 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
368 #[cfg(feature = "time")]
369 fn test_pginterval_timerust-analyzer cargo sqlx-postgres 0.8.3 types/interval/test_pginterval_time().() {
370 // Case for positive duration
371 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
372 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
373 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
374 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: 27_000,
375 };
376 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
377 &PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`]try_from().(timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#::microsecondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]microseconds().(27_000)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
378 &interval
379 );
380
381 // Case for negative duration
382 let interval = PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval# {
383 daysrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#days.: 0,
384 monthsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#months.: 0,
385 microsecondsrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#microseconds.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().27_000,
386 };
387 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
388 &PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`]try_from().(timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#::microsecondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]microseconds().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().27_000)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
389 &interval
390 );
391
392 // Case when precision loss occurs
393 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`]try_from().(timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#::nanosecondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]nanoseconds().(27_000_001)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
394 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`]try_from().(timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#::nanosecondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]nanoseconds().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().27_000_001)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
395
396 // Case when microsecond overflow occurs
397 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`]try_from().(timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#::secondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]seconds().(10_000_000_000_000)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
398 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(PgIntervalrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/PgInterval#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/interval/impl#[PgInterval][`TryFrom<time::SignedDuration>`]try_from().(timerust-analyzer cargo time 0.3.55 crate/::Durationrust-analyzer cargo time 0.3.55 Duration#::secondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]seconds().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().10_000_000_000_000)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
399 }