| 1 | use bytesrust-analyzer cargo bytes 1.11.1 crate/::BytesMutrust-analyzer cargo bytes 1.11.1 bytes_mut/BytesMut#; |
| 2 | use postgres_protocolrust-analyzer cargo postgres-protocol 0.6.12 crate/::typesrust-analyzer cargo postgres-protocol 0.6.12 types/; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#; |
| 4 | |
| 5 | use craterust-analyzer cargo postgres-types 0.2.14 crate/::{FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#, IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#, ToSqlrust-analyzer cargo postgres-types 0.2.14 ToSql#, Typerust-analyzer cargo postgres-types 0.2.14 Type#}; |
| 6 | |
| 7 | /// A wrapper that can be used to represent infinity with `Type::Date` types. |
| 8 | #[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:, 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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 9 | pub enum Daterust-analyzer cargo postgres-types 0.2.14 special/Date#<T> { |
| 10 | /// Represents `infinity`, a date that is later than all other dates. |
| 11 | PosInfinityrust-analyzer cargo postgres-types 0.2.14 special/Date#PosInfinity#, |
| 12 | /// Represents `-infinity`, a date that is earlier than all other dates. |
| 13 | NegInfinityrust-analyzer cargo postgres-types 0.2.14 special/Date#NegInfinity#, |
| 14 | /// The wrapped date. |
| 15 | Valuerust-analyzer cargo postgres-types 0.2.14 special/Date#Value#(T), |
| 16 | } |
| 17 | |
| 18 | impl<'a, T: FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#<'a>> FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#<'a> for Daterust-analyzer cargo postgres-types 0.2.14 special/Date#<T> { |
| 19 | fn from_sqlrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Date<T>`][`FromSql<'a>`]from_sql().(ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#, raw: &'a [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Date<T>`][`FromSql<'a>`], Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>> { |
| 20 | match typesrust-analyzer cargo postgres-protocol 0.6.12 types/::date_from_sqlrust-analyzer cargo postgres-protocol 0.6.12 types/date_from_sql().(raw)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 21 | i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX. => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Daterust-analyzer cargo postgres-types 0.2.14 special/Date#::PosInfinityrust-analyzer cargo postgres-types 0.2.14 special/Date#PosInfinity#), |
| 22 | i32::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MIN. => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Daterust-analyzer cargo postgres-types 0.2.14 special/Date#::NegInfinityrust-analyzer cargo postgres-types 0.2.14 special/Date#NegInfinity#), |
| 23 | _ => T::from_sqlrust-analyzer cargo postgres-types 0.2.14 FromSql#from_sql().(ty, raw).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Daterust-analyzer cargo postgres-types 0.2.14 special/Date#::Valuerust-analyzer cargo postgres-types 0.2.14 special/Date#Value#), |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | fn acceptsrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Date<T>`][`FromSql<'a>`]accepts().(ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#) -> bool { |
| 28 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ty rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq().==rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq(). rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq().Typerust-analyzer cargo postgres-types 0.2.14 Type#::DATErust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]DATE. && T::acceptsrust-analyzer cargo postgres-types 0.2.14 FromSql#accepts().(ty) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl<T: ToSqlrust-analyzer cargo postgres-types 0.2.14 ToSql#> ToSqlrust-analyzer cargo postgres-types 0.2.14 ToSql# for Daterust-analyzer cargo postgres-types 0.2.14 special/Date#<T> { |
| 33 | fn to_sqlrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Date<T>`][ToSql]to_sql().( |
| 34 | &self, |
| 35 | ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#, |
| 36 | out: &mut BytesMutrust-analyzer cargo bytes 1.11.1 bytes_mut/BytesMut#, |
| 37 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>> { |
| 38 | let value = match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 39 | Daterust-analyzer cargo postgres-types 0.2.14 special/Date#::PosInfinityrust-analyzer cargo postgres-types 0.2.14 special/Date#PosInfinity# => i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX., |
| 40 | Daterust-analyzer cargo postgres-types 0.2.14 special/Date#::NegInfinityrust-analyzer cargo postgres-types 0.2.14 special/Date#NegInfinity# => i32::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MIN., |
| 41 | Daterust-analyzer cargo postgres-types 0.2.14 special/Date#::Valuerust-analyzer cargo postgres-types 0.2.14 special/Date#Value#(ref v) => return v.to_sqlrust-analyzer cargo postgres-types 0.2.14 ToSql#to_sql().(ty, out), |
| 42 | }; |
| 43 | |
| 44 | typesrust-analyzer cargo postgres-protocol 0.6.12 types/::date_to_sqlrust-analyzer cargo postgres-protocol 0.6.12 types/date_to_sql().(value, out); |
| 45 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#::Norust-analyzer cargo postgres-types 0.2.14 IsNull#No#) |
| 46 | } |
| 47 | |
| 48 | fn acceptsrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Date<T>`][ToSql]accepts().(ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#) -> bool { |
| 49 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ty rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq().==rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq(). rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq().Typerust-analyzer cargo postgres-types 0.2.14 Type#::DATErust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]DATE. && T::acceptsrust-analyzer cargo postgres-types 0.2.14 ToSql#accepts().(ty) |
| 50 | } |
| 51 | |
| 52 | to_sql_checkedrust-analyzer cargo postgres-types 0.2.14 to_sql_checked!!(); |
| 53 | } |
| 54 | |
| 55 | /// A wrapper that can be used to represent infinity with `Type::Timestamp` and `Type::Timestamptz` |
| 56 | /// types. |
| 57 | #[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:, 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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 58 | pub enum Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#<T> { |
| 59 | /// Represents `infinity`, a timestamp that is later than all other timestamps. |
| 60 | PosInfinityrust-analyzer cargo postgres-types 0.2.14 special/Timestamp#PosInfinity#, |
| 61 | /// Represents `-infinity`, a timestamp that is earlier than all other timestamps. |
| 62 | NegInfinityrust-analyzer cargo postgres-types 0.2.14 special/Timestamp#NegInfinity#, |
| 63 | /// The wrapped timestamp. |
| 64 | Valuerust-analyzer cargo postgres-types 0.2.14 special/Timestamp#Value#(T), |
| 65 | } |
| 66 | |
| 67 | impl<'a, T: FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#<'a>> FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#<'a> for Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#<T> { |
| 68 | fn from_sqlrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Timestamp<T>`][`FromSql<'a>`]from_sql().(ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#, raw: &'a [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Timestamp<T>`][`FromSql<'a>`], Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>> { |
| 69 | match typesrust-analyzer cargo postgres-protocol 0.6.12 types/::timestamp_from_sqlrust-analyzer cargo postgres-protocol 0.6.12 types/timestamp_from_sql().(raw)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 70 | i64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MAX. => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#::PosInfinityrust-analyzer cargo postgres-types 0.2.14 special/Timestamp#PosInfinity#), |
| 71 | i64::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MIN. => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#::NegInfinityrust-analyzer cargo postgres-types 0.2.14 special/Timestamp#NegInfinity#), |
| 72 | _ => T::from_sqlrust-analyzer cargo postgres-types 0.2.14 FromSql#from_sql().(ty, raw).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#::Valuerust-analyzer cargo postgres-types 0.2.14 special/Timestamp#Value#), |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | fn acceptsrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Timestamp<T>`][`FromSql<'a>`]accepts().(ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#) -> bool { |
| 77 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ty, Typerust-analyzer cargo postgres-types 0.2.14 Type#::TIMESTAMPrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]TIMESTAMP. | Typerust-analyzer cargo postgres-types 0.2.14 Type#::TIMESTAMPTZrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]TIMESTAMPTZ. if T::acceptsrust-analyzer cargo postgres-types 0.2.14 FromSql#accepts().(ty)) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | impl<T: ToSqlrust-analyzer cargo postgres-types 0.2.14 ToSql#> ToSqlrust-analyzer cargo postgres-types 0.2.14 ToSql# for Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#<T> { |
| 82 | fn to_sqlrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Timestamp<T>`][ToSql]to_sql().( |
| 83 | &self, |
| 84 | ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#, |
| 85 | out: &mut BytesMutrust-analyzer cargo bytes 1.11.1 bytes_mut/BytesMut#, |
| 86 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>> { |
| 87 | let value = match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 88 | Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#::PosInfinityrust-analyzer cargo postgres-types 0.2.14 special/Timestamp#PosInfinity# => i64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MAX., |
| 89 | Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#::NegInfinityrust-analyzer cargo postgres-types 0.2.14 special/Timestamp#NegInfinity# => i64::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MIN., |
| 90 | Timestamprust-analyzer cargo postgres-types 0.2.14 special/Timestamp#::Valuerust-analyzer cargo postgres-types 0.2.14 special/Timestamp#Value#(ref v) => return v.to_sqlrust-analyzer cargo postgres-types 0.2.14 ToSql#to_sql().(ty, out), |
| 91 | }; |
| 92 | |
| 93 | typesrust-analyzer cargo postgres-protocol 0.6.12 types/::timestamp_to_sqlrust-analyzer cargo postgres-protocol 0.6.12 types/timestamp_to_sql().(value, out); |
| 94 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#::Norust-analyzer cargo postgres-types 0.2.14 IsNull#No#) |
| 95 | } |
| 96 | |
| 97 | fn acceptsrust-analyzer cargo postgres-types 0.2.14 special/impl#[`Timestamp<T>`][ToSql]accepts().(ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#) -> bool { |
| 98 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ty, Typerust-analyzer cargo postgres-types 0.2.14 Type#::TIMESTAMPrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]TIMESTAMP. | Typerust-analyzer cargo postgres-types 0.2.14 Type#::TIMESTAMPTZrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]TIMESTAMPTZ. if T::acceptsrust-analyzer cargo postgres-types 0.2.14 ToSql#accepts().(ty)) |
| 99 | } |
| 100 | |
| 101 | to_sql_checkedrust-analyzer cargo postgres-types 0.2.14 to_sql_checked!!(); |
| 102 | } |