Debian Codegraph @

src/types/chrono/time.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/::Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#;
5 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#};
6 use chronorust-analyzer cargo chrono 0.4.45 crate/::{Durationrust-analyzer cargo chrono 0.4.45 Duration#, NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime#};
7 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/;
8
9 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime# {
10 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/time/impl#[NaiveTime][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
11 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMErust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIME.
12 }
13 }
14
15 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime# {
16 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/time/impl#[NaiveTime][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
17 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIME_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIME_ARRAY.
18 }
19 }
20
21 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime# {
22 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/time/impl#[NaiveTime][`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#> {
23 // TIME is encoded as the microseconds since midnight
24 let micros = (*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/time/impl#[NaiveTime][`Sub<Self>`]sub().-rust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime][`Sub<Self>`]sub(). rust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime][`Sub<Self>`]sub().NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime#::defaultrust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime][Default]default().())
25 .num_microsecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]num_microseconds().()
26 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Time out of range for PostgreSQL: {self}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
27
28 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)
29 }
30
31 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/time/impl#[NaiveTime][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
32 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().::<u64>()
33 }
34 }
35
36 impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime# {
37 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/time/impl#[NaiveTime][`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/time/impl#[NaiveTime][`Decode<'r, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
38 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().() {
39 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Binaryrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Binary# => {
40 // TIME is encoded as the microseconds since midnight
41 let us: i64 = 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().;
42 NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime#::defaultrust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime][Default]default().() rust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime][`Add<TimeDelta>`]add().+rust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime][`Add<TimeDelta>`]add(). rust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime][`Add<TimeDelta>`]add().Durationrust-analyzer cargo chrono 0.4.45 Duration#::microsecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]microseconds().(us)
43 }
44
45 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Textrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Text# => NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime#::parse_from_strrust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime]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()., "%H:%M:%S%.f")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
46 })
47 }
48 }
49
50 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
51 fn check_naive_time_default_is_midnightrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/time/check_naive_time_default_is_midnight().() {
52 // Just a canary in case this changes.
53 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
54 NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime#::from_hms_optrust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime]from_hms_opt().(0, 0, 0),
55 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NaiveTimerust-analyzer cargo chrono 0.4.45 naive/time/NaiveTime#::defaultrust-analyzer cargo chrono 0.4.45 naive/time/impl#[NaiveTime][Default]default().()),
56 "implementation assumes `NaiveTime::default()` equals midnight"
57 );
58 }