| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#}; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#}; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 4 | |
| 5 | 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#}; |
| 6 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 7 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::extrust-analyzer cargo sqlx-core 0.8.3 ext/::ustrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/::UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#; |
| 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/::{PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection#, PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#}; |
| 10 | |
| 11 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::type_inforust-analyzer cargo sqlx-postgres 0.8.3 type_info/::PgArrayOfrust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgArrayOf#; |
| 12 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::argumentsrust-analyzer cargo sqlx-core 0.8.3 arguments/::Argumentsrust-analyzer cargo sqlx-core 0.8.3 arguments/Arguments#; |
| 13 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::errorrust-analyzer cargo sqlx-core 0.8.3 error/::BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#; |
| 14 | |
| 15 | // TODO: buf.patch(|| ...) is a poor name, can we think of a better name? Maybe `buf.lazy(||)` ? |
| 16 | // TODO: Extend the patch system to support dynamic lengths |
| 17 | // Considerations: |
| 18 | // - The prefixed-len offset needs to be back-tracked and updated |
| 19 | // - message::Bind needs to take a &PgArguments and use a `write` method instead of |
| 20 | // referencing a buffer directly |
| 21 | // - The basic idea is that we write bytes for the buffer until we get somewhere |
| 22 | // that has a patch, we then apply the patch which should write to &mut Vec<u8>, |
| 23 | // backtrack and update the prefixed-len, then write until the next patch offset |
| 24 | |
| 25 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 26 | pub struct PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer# { |
| 27 | bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#buffer.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 28 | |
| 29 | // Number of arguments |
| 30 | countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#count.: usize, |
| 31 | |
| 32 | // Whenever an `Encode` impl needs to defer some work until after we resolve parameter types |
| 33 | // it can use `patch`. |
| 34 | // |
| 35 | // This currently is only setup to be useful if there is a *fixed-size* slot that needs to be |
| 36 | // tweaked from the input type. However, that's the only use case we currently have. |
| 37 | patchesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#patches.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Patchrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#>, |
| 38 | |
| 39 | // Whenever an `Encode` impl encounters a `PgTypeInfo` object that does not have an OID |
| 40 | // It pushes a "hole" that must be patched later. |
| 41 | // |
| 42 | // The hole is a `usize` offset into the buffer with the type name that should be resolved |
| 43 | // This is done for Records and Arrays as the OID is needed well before we are in an async |
| 44 | // function and can just ask postgres. |
| 45 | // |
| 46 | type_holesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#type_holes.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(usize, HoleKindrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#)>, // Vec<{ offset, type_name }> |
| 47 | } |
| 48 | |
| 49 | enum HoleKindrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind# { |
| 50 | Typerust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Type# { namerust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Type#name.: UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# }, |
| 51 | Arrayrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Array#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<PgArrayOfrust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgArrayOf#>), |
| 52 | } |
| 53 | |
| 54 | struct Patchrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch# { |
| 55 | buf_offsetrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#buf_offset.: usize, |
| 56 | arg_indexrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#arg_index.: usize, |
| 57 | #[allow(clippy::type_complexity)] |
| 58 | callbackrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#callback.: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&mut [u8], &PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#) + 'static + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>, |
| 59 | } |
| 60 | |
| 61 | /// Implementation of [`Arguments`] for PostgreSQL. |
| 62 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 63 | pub struct PgArgumentsrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments# { |
| 64 | // Types of each bind parameter |
| 65 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) typesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#types.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#>, |
| 66 | |
| 67 | // Buffer of encoded bind parameters |
| 68 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer.: PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#, |
| 69 | } |
| 70 | |
| 71 | impl PgArgumentsrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments# { |
| 72 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) fn addrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments]add().<'q, T>(&mut self, value: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> |
| 73 | where |
| 74 | T: Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'q, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> + Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>, |
| 75 | { |
| 76 | let type_info = value.producesrust-analyzer cargo sqlx-core 0.8.3 encode/Encode#produces().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(T::type_inforust-analyzer cargo sqlx-core 0.8.3 types/Type#type_info().); |
| 77 | |
| 78 | let buffer_snapshot = self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer..snapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]snapshot().(); |
| 79 | |
| 80 | // encode the value into our buffer |
| 81 | if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer..encoderust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]encode().(value) { |
| 82 | // reset the value buffer to its previous value if encoding failed, |
| 83 | // so we don't leave a half-encoded value behind |
| 84 | self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer..reset_to_snapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]reset_to_snapshot().(buffer_snapshot); |
| 85 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error); |
| 86 | }; |
| 87 | |
| 88 | // remember the type information for this value |
| 89 | self.typesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#types..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(type_info); |
| 90 | // increment the number of arguments we are tracking |
| 91 | self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer..countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 92 | |
| 93 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 94 | } |
| 95 | |
| 96 | // Apply patches |
| 97 | // This should only go out and ask postgres if we have not seen the type name yet |
| 98 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) async fn apply_patchesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments]apply_patches().( |
| 99 | &mut self, |
| 100 | conn: &mut PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection#, |
| 101 | parameters: &[PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#], |
| 102 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 103 | let PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer# { |
| 104 | ref patchesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#patches., |
| 105 | ref type_holesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#type_holes., |
| 106 | ref mut bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#buffer., |
| 107 | .. |
| 108 | } = self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer.; |
| 109 | |
| 110 | for patch in patches { |
| 111 | let buf = &mut buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().patch.buf_offsetrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#buf_offset...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().; |
| 112 | let ty = ¶meters[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().patch.arg_indexrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#arg_index.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 113 | |
| 114 | (patch.callbackrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#callback.)(buf, ty); |
| 115 | } |
| 116 | |
| 117 | for (offset, kind) in type_holes { |
| 118 | let oid = match kind { |
| 119 | HoleKindrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#::Typerust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Type# { namerust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Type#name. } => conn.fetch_type_id_by_namerust-analyzer cargo sqlx-postgres 0.8.3 connection/describe/impl#[PgConnection]fetch_type_id_by_name().(name).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 120 | HoleKindrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#::Arrayrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Array#(array) => conn.fetch_array_type_idrust-analyzer cargo sqlx-postgres 0.8.3 connection/describe/impl#[PgConnection]fetch_array_type_id().(array).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 121 | }; |
| 122 | buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().4)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&oid.0rust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#0..to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().()); |
| 123 | } |
| 124 | |
| 125 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | impl<'q> Argumentsrust-analyzer cargo sqlx-core 0.8.3 arguments/Arguments#<'q> for PgArgumentsrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments# { |
| 130 | type Databaserust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments][`Arguments<'q>`]Database# = Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#; |
| 131 | |
| 132 | fn reserverust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments][`Arguments<'q>`]reserve().(&mut self, additional: usize, size: usize) { |
| 133 | self.typesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#types..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(additional); |
| 134 | self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(size); |
| 135 | } |
| 136 | |
| 137 | fn addrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments][`Arguments<'q>`]add().<T>(&mut self, value: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> |
| 138 | where |
| 139 | T: Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'q, Selfrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments][`Arguments<'q>`]::Databaserust-analyzer cargo sqlx-core 0.8.3 arguments/Arguments#Database#> + Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments][`Arguments<'q>`]::Databaserust-analyzer cargo sqlx-core 0.8.3 arguments/Arguments#Database#>, |
| 140 | { |
| 141 | self.addrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments]add().(value) |
| 142 | } |
| 143 | |
| 144 | fn format_placeholderrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments][`Arguments<'q>`]format_placeholder().<W: Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#>(&self, writer: &mut W) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 145 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "${}", self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer..countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#count.) |
| 146 | } |
| 147 | |
| 148 | #[inline(always)] |
| 149 | fn lenrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArguments][`Arguments<'q>`]len().(&self) -> usize { |
| 150 | self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArguments#buffer..countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#count. |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | impl PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer# { |
| 155 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) fn encoderust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]encode().<'q, T>(&mut self, value: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> |
| 156 | where |
| 157 | T: Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'q, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>, |
| 158 | { |
| 159 | // Won't catch everything but is a good sanity check |
| 160 | value_size_int4_checkedrust-analyzer cargo sqlx-postgres 0.8.3 arguments/value_size_int4_checked().(value.size_hintrust-analyzer cargo sqlx-core 0.8.3 encode/Encode#size_hint().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 161 | |
| 162 | // reserve space to write the prefixed length of the value |
| 163 | let offset = self.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 164 | |
| 165 | self.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&[0; 4]); |
| 166 | |
| 167 | // encode the value into our buffer |
| 168 | let len = if let IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#::Norust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#No# = value.encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#encode().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 169 | // Ensure that the value size does not overflow i32 |
| 170 | value_size_int4_checkedrust-analyzer cargo sqlx-postgres 0.8.3 arguments/value_size_int4_checked().(self.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().4)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 171 | } else { |
| 172 | // Write a -1 to indicate NULL |
| 173 | // NOTE: It is illegal for [encode] to write any data |
| 174 | debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(self.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), offset +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 4); |
| 175 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1_i32 |
| 176 | }; |
| 177 | |
| 178 | // write the len to the beginning of the value |
| 179 | // (offset + 4) cannot overflow because it would have failed at `self.extend()`. |
| 180 | self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().4)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&len.to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]to_be_bytes().()); |
| 181 | |
| 182 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 183 | } |
| 184 | |
| 185 | // Adds a callback to be invoked later when we know the parameter type |
| 186 | #[allow(dead_code)] |
| 187 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) fn patchrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]patch().<F>(&mut self, callback: F) |
| 188 | where |
| 189 | F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&mut [u8], &PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#) + 'static + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, |
| 190 | { |
| 191 | let offset = self.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 192 | let arg_index = self.countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#count.; |
| 193 | |
| 194 | self.patchesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#patches..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Patchrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch# { |
| 195 | buf_offsetrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#buf_offset.: offset, |
| 196 | arg_indexrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#arg_index., |
| 197 | callbackrust-analyzer cargo sqlx-postgres 0.8.3 arguments/Patch#callback.: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(callback), |
| 198 | }); |
| 199 | } |
| 200 | |
| 201 | // Extends the inner buffer by enough space to have an OID |
| 202 | // Remembers where the OID goes and type name for the OID |
| 203 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) fn patch_type_by_namerust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]patch_type_by_name().(&mut self, type_name: &UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#) { |
| 204 | let offset = self.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 205 | |
| 206 | self.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&0_u32.to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().()); |
| 207 | self.type_holesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#type_holes..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(( |
| 208 | offset, |
| 209 | HoleKindrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#::Typerust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Type# { |
| 210 | namerust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Type#name.: type_name.clonerust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Clone]clone().(), |
| 211 | }, |
| 212 | )); |
| 213 | } |
| 214 | |
| 215 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) fn patch_array_typerust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]patch_array_type().(&mut self, array: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<PgArrayOfrust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgArrayOf#>) { |
| 216 | let offset = self.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 217 | |
| 218 | self.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&0_u32.to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().()); |
| 219 | self.type_holesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#type_holes..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((offset, HoleKindrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#::Arrayrust-analyzer cargo sqlx-postgres 0.8.3 arguments/HoleKind#Array#(array))); |
| 220 | } |
| 221 | |
| 222 | fn snapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]snapshot().(&self) -> PgArgumentBufferSnapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot# { |
| 223 | let Selfrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer] { |
| 224 | bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#buffer., |
| 225 | countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#count., |
| 226 | patchesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#patches., |
| 227 | type_holesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#type_holes., |
| 228 | } = self; |
| 229 | |
| 230 | PgArgumentBufferSnapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot# { |
| 231 | buffer_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#buffer_length.: buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 232 | countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#count.: *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().count, |
| 233 | patches_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#patches_length.: patches.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 234 | type_holes_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#type_holes_length.: type_holes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | fn reset_to_snapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer]reset_to_snapshot().( |
| 239 | &mut self, |
| 240 | PgArgumentBufferSnapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot# { |
| 241 | buffer_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#buffer_length., |
| 242 | countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#count., |
| 243 | patches_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#patches_length., |
| 244 | type_holes_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#type_holes_length., |
| 245 | }: PgArgumentBufferSnapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#, |
| 246 | ) { |
| 247 | self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#buffer..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(buffer_length); |
| 248 | self.countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#count. = count; |
| 249 | self.patchesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#patches..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(patches_length); |
| 250 | self.type_holesrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#type_holes..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(type_holes_length); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | struct PgArgumentBufferSnapshotrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot# { |
| 255 | buffer_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#buffer_length.: usize, |
| 256 | countrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#count.: usize, |
| 257 | patches_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#patches_length.: usize, |
| 258 | type_holes_lengthrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBufferSnapshot#type_holes_length.: usize, |
| 259 | } |
| 260 | |
| 261 | impl Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer# { |
| 262 | type Targetrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]Target# = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>; |
| 263 | |
| 264 | #[inline] |
| 265 | fn derefrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]deref().(&self) -> &Selfrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][Deref]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# { |
| 266 | &self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#buffer. |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | impl DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer# { |
| 271 | #[inline] |
| 272 | fn deref_mutrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][DerefMut]deref_mut().(&mut self) -> &mut Selfrust-analyzer cargo sqlx-postgres 0.8.3 arguments/impl#[PgArgumentBuffer][DerefMut]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# { |
| 273 | &mut self.bufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#buffer. |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) fn value_size_int4_checkedrust-analyzer cargo sqlx-postgres 0.8.3 arguments/value_size_int4_checked().(size: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i32, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 278 | i32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[i32][`TryFrom<usize>`]try_from().(size).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| { |
| 279 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 280 | "value size would overflow in the binary protocol encoding: {size} > {}", |
| 281 | i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX. |
| 282 | ) |
| 283 | }) |
| 284 | } |