Debian Codegraph @

src/types/time/datetime.rs

raw symbols SCIP
1 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#;
2 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#};
3 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#;
4 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::typesrust-analyzer cargo sqlx-postgres 0.8.3 types/::timerust-analyzer cargo sqlx-postgres 0.8.3 types/time/::PG_EPOCHrust-analyzer cargo sqlx-postgres 0.8.3 types/time/PG_EPOCH.;
5 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#;
6 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#};
7 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
8 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/;
9 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!;
10 use timerust-analyzer cargo time 0.3.55 crate/::macrosrust-analyzer cargo time 0.3.55 macros/::offsetrust-analyzer cargo time-macros 0.2.32 offset!;
11 use timerust-analyzer cargo time 0.3.55 crate/::{Durationrust-analyzer cargo time 0.3.55 Duration#, OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime#, PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#};
12
13 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# {
14 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[`time::PlainDateTime`][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
15 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMESTAMPrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIMESTAMP.
16 }
17 }
18
19 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime# {
20 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[OffsetDateTime][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
21 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMESTAMPTZrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIMESTAMPTZ.
22 }
23 }
24
25 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# {
26 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[`time::PlainDateTime`][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
27 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMESTAMP_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIMESTAMP_ARRAY.
28 }
29 }
30
31 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime# {
32 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[OffsetDateTime][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
33 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMESTAMPTZ_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIMESTAMPTZ_ARRAY.
34 }
35 }
36
37 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# {
38 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[`time::PlainDateTime`][`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#> {
39 // TIMESTAMP is encoded as the microseconds since the epoch
40 let micros: i64 = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime][`Sub<Self>`]sub().-rust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime][`Sub<Self>`]sub(). rust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime][`Sub<Self>`]sub().PG_EPOCHrust-analyzer cargo sqlx-postgres 0.8.3 types/time/PG_EPOCH..midnightrust-analyzer cargo time 0.3.55 date/impl#[Date]midnight().())
41 .whole_microsecondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]whole_microseconds().()
42 .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()
43 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| {
44 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("value {self:?} would overflow binary encoding for Postgres TIME")
45 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
46 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/Encode#encode().(micros, buf)
47 }
48
49 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[`time::PlainDateTime`][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
50 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>()
51 }
52 }
53
54 impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# {
55 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[`time::PlainDateTime`][`Decode<'r, Postgres>`]decode().(value: PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[`time::PlainDateTime`][`Decode<'r, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
56 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match value.formatrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]format().() {
57 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Binaryrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Binary# => {
58 // TIMESTAMP is encoded as the microseconds since the epoch
59 let us = Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::decoderust-analyzer cargo sqlx-postgres 0.8.3 types/int/impl#[i64][`Decode<'_, Postgres>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
60 PG_EPOCHrust-analyzer cargo sqlx-postgres 0.8.3 types/time/PG_EPOCH..midnightrust-analyzer cargo time 0.3.55 date/impl#[Date]midnight().() rust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime][`Add<SignedDuration>`]add().+rust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime][`Add<SignedDuration>`]add(). rust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime][`Add<SignedDuration>`]add().Durationrust-analyzer cargo time 0.3.55 Duration#::microsecondsrust-analyzer cargo time 0.3.55 signed_duration/impl#[SignedDuration]microseconds().(us)
61 }
62
63 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Textrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Text# => {
64 let s = value.as_strrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]as_str().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
65
66 // If there is no decimal point we need to add one.
67 let s = if s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('.') {
68 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(s)
69 } else {
70 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{s}.0"))
71 };
72
73 // Contains a time-zone specifier
74 // This is given for timestamptz for some reason
75 // Postgres already guarantees this to always be UTC
76 if s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('+') {
77 PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#::parserust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]parse().(&s, &format_descriptionrust-analyzer cargo time-macros 0.2.32 format_description!!("[year]-[month]-[day] [hour]:[minute]:[second].[subsecond][offset_hour]"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
78 } else {
79 PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#::parserust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]parse().(
80 &s,
81 &format_descriptionrust-analyzer cargo time-macros 0.2.32 format_description!!(
82 "[year]-[month]-[day] [hour]:[minute]:[second].[subsecond]"
83 ),
84 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
85 }
86 }
87 })
88 }
89 }
90
91 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime# {
92 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[OffsetDateTime][`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#> {
93 let utc = self.to_offsetrust-analyzer cargo time 0.3.55 offset_date_time/impl#[OffsetDateTime]to_offset().(offsetrust-analyzer cargo time-macros 0.2.32 offset!!(UTC));
94 let primitive = PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime#::newrust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]new().(utc.daterust-analyzer cargo time 0.3.55 offset_date_time/impl#[OffsetDateTime]date().(), utc.timerust-analyzer cargo time 0.3.55 offset_date_time/impl#[OffsetDateTime]time().());
95
96 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/Encode#encode().(primitive, buf)
97 }
98
99 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[OffsetDateTime][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
100 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>()
101 }
102 }
103
104 impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for OffsetDateTimerust-analyzer cargo time 0.3.55 offset_date_time/OffsetDateTime# {
105 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[OffsetDateTime][`Decode<'r, Postgres>`]decode().(value: PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[OffsetDateTime][`Decode<'r, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
106 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(<PrimitiveDateTimerust-analyzer cargo time 0.3.55 PrimitiveDateTime# as Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>>::decoderust-analyzer cargo sqlx-postgres 0.8.3 types/time/datetime/impl#[`time::PlainDateTime`][`Decode<'r, Postgres>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..assume_utcrust-analyzer cargo time 0.3.55 plain_date_time/impl#[PlainDateTime]assume_utc().())
107 }
108 }