| 1 | 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#, UnexpectedNullErrorrust-analyzer cargo sqlx-core 0.8.3 error/UnexpectedNullError#}; |
| 2 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::{PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#}; |
| 3 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::bytesrust-analyzer cargo bytes 1.12.1 crate/::{Bufrust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#, Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#}; |
| 4 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::valuerust-analyzer cargo sqlx-core 0.8.3 value/::{Valuerust-analyzer cargo sqlx-core 0.8.3 value/Value#, ValueRefrust-analyzer cargo sqlx-core 0.8.3 value/ValueRef#}; |
| 5 | 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#; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().; |
| 7 | |
| 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:, 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:)] |
| 9 | #[repr(u8)] |
| 10 | pub enum PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat# { |
| 11 | Textrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Text# = 0, |
| 12 | Binaryrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Binary# = 1, |
| 13 | } |
| 14 | |
| 15 | /// Implementation of [`ValueRef`] for PostgreSQL. |
| 16 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 17 | pub struct PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r> { |
| 18 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#value.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'r [u8]>, |
| 19 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) rowrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#row.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'r Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#>, |
| 20 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#type_info.: PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#, |
| 21 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) formatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#format.: PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#, |
| 22 | } |
| 23 | |
| 24 | /// Implementation of [`Value`] for PostgreSQL. |
| 25 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 26 | pub struct PgValuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue# { |
| 27 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#value.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#>, |
| 28 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#type_info.: PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#, |
| 29 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) formatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#format.: PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#, |
| 30 | } |
| 31 | |
| 32 | impl<'r> PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r> { |
| 33 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) fn getrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]get().( |
| 34 | buf: &mut &'r [u8], |
| 35 | format: PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#, |
| 36 | ty: PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#, |
| 37 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`], Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 38 | let element_len = buf.get_i32rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_i32().(); |
| 39 | |
| 40 | let element_val = if element_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1 { |
| 41 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 42 | } else { |
| 43 | let element_len: usize = element_len |
| 44 | .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() |
| 45 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("overflow converting element_len ({element_len}) to usize"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 46 | |
| 47 | let val = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#element_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 48 | buf.advancerust-analyzer cargo bytes 1.12.1 buf/buf_impl/impl#[`&[u8]`][Buf]advance().(element_len); |
| 49 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) |
| 50 | }; |
| 51 | |
| 52 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef# { |
| 53 | valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#value.: element_val, |
| 54 | rowrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#row.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 55 | type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#type_info.: ty, |
| 56 | formatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#format., |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | pub fn formatrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]format().(&self) -> PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat# { |
| 61 | self.formatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#format. |
| 62 | } |
| 63 | |
| 64 | pub fn as_bytesrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]as_bytes().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'r [u8], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 65 | match &self.valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#value. { |
| 66 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v), |
| 67 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(UnexpectedNullErrorrust-analyzer cargo sqlx-core 0.8.3 error/UnexpectedNullError#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | pub fn as_strrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]as_str().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'r str, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 72 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(self.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().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | impl Valuerust-analyzer cargo sqlx-core 0.8.3 value/Value# for PgValuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue# { |
| 77 | type Databaserust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[PgValue][Value]Database# = Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#; |
| 78 | |
| 79 | #[inline] |
| 80 | fn as_refrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[PgValue][Value]as_ref().(&self) -> PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'_> { |
| 81 | PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef# { |
| 82 | valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#value.: self.valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#value..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(), |
| 83 | rowrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#row.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 84 | type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#type_info.: self.type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#type_info..clonerust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo][Clone]clone().(), |
| 85 | formatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#format.: self.formatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#format., |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[PgValue][Value]type_info().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#> { |
| 90 | 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#(&self.type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#type_info.) |
| 91 | } |
| 92 | |
| 93 | fn is_nullrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[PgValue][Value]is_null().(&self) -> bool { |
| 94 | self.valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#value..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | impl<'r> ValueRefrust-analyzer cargo sqlx-core 0.8.3 value/ValueRef#<'r> for PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r> { |
| 99 | type Databaserust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`][`ValueRef<'r>`]Database# = Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#; |
| 100 | |
| 101 | fn to_ownedrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`][`ValueRef<'r>`]to_owned().(&self) -> PgValuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue# { |
| 102 | let value = match (self.rowrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#row., self.valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#value.) { |
| 103 | (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row.slice_refrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]slice_ref().(value)), |
| 104 | |
| 105 | (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::copy_from_slicerust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]copy_from_slice().(value)), |
| 106 | |
| 107 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 108 | }; |
| 109 | |
| 110 | PgValuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue# { |
| 111 | valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#value., |
| 112 | formatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#format.: self.formatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#format., |
| 113 | type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValue#type_info.: self.type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#type_info..clonerust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo][Clone]clone().(), |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`][`ValueRef<'r>`]type_info().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#> { |
| 118 | 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#(&self.type_inforust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#type_info.) |
| 119 | } |
| 120 | |
| 121 | fn is_nullrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`][`ValueRef<'r>`]is_null().(&self) -> bool { |
| 122 | self.valuerust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#value..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 123 | } |
| 124 | } |