Debian Codegraph @

src/types/chrono/date.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 chronorust-analyzer cargo chrono 0.4.45 crate/::{NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#, TimeDeltarust-analyzer cargo chrono 0.4.45 time_delta/TimeDelta#};
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 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate# {
12 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/date/impl#[NaiveDate][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
13 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::DATErust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]DATE.
14 }
15 }
16
17 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate# {
18 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/date/impl#[NaiveDate][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
19 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::DATE_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]DATE_ARRAY.
20 }
21 }
22
23 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate# {
24 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/date/impl#[NaiveDate][`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#> {
25 // DATE is encoded as the days since epoch
26 let days: i32 = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate][`Sub<Self>`]sub().-rust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate][`Sub<Self>`]sub(). rust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate][`Sub<Self>`]sub().postgres_epoch_daterust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/date/postgres_epoch_date().())
27 .num_daysrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]num_days().()
28 .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()
29 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| {
30 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("value {self:?} would overflow binary encoding for Postgres DATE")
31 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
32
33 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().(days, buf)
34 }
35
36 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/date/impl#[NaiveDate][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
37 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().::<i32>()
38 }
39 }
40
41 impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate# {
42 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/date/impl#[NaiveDate][`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/chrono/date/impl#[NaiveDate][`Decode<'r, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
43 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().() {
44 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Binaryrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Binary# => {
45 // DATE is encoded as the days since epoch
46 let days: i32 = 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#[i32][`Decode<'_, Postgres>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
47
48 let days = TimeDeltarust-analyzer cargo chrono 0.4.45 time_delta/TimeDelta#::try_daysrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]try_days().(days.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
49 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| {
50 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("BUG: days ({days}) as `i32` multiplied into seconds should not overflow `i64`")
51 });
52
53 postgres_epoch_daterust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/date/postgres_epoch_date().() rust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate][`Add<TimeDelta>`]add().+rust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate][`Add<TimeDelta>`]add(). rust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate][`Add<TimeDelta>`]add().days
54 }
55
56 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Textrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Text# => NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#::parse_from_strrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]parse_from_str().(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()., "%Y-%m-%d")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
57 })
58 }
59 }
60
61 #[inline]
62 fn postgres_epoch_daterust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/date/postgres_epoch_date().() -> NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate# {
63 NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#::from_ymd_optrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]from_ymd_opt().(2000, 1, 1).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("expected 2000-01-01 to be a valid NaiveDate")
64 }