Debian Codegraph @

src/io/buf_mut.rs

raw symbols SCIP
1 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::iorust-analyzer cargo sqlx-postgres 0.8.3 io/::{PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#, StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#};
2
3 pub trait PgBufMutExtrust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/PgBufMutExt# {
4 fn put_length_prefixedrust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/PgBufMutExt#put_length_prefixed().<F>(&mut self, f: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>
5 where
6 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>;
7
8 fn put_statement_namerust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/PgBufMutExt#put_statement_name().(&mut self, id: StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#);
9
10 fn put_portal_namerust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/PgBufMutExt#put_portal_name().(&mut self, id: PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#);
11 }
12
13 impl PgBufMutExtrust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/PgBufMutExt# for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
14 // writes a length-prefixed message, this is used when encoding nearly all messages as postgres
15 // wants us to send the length of the often-variable-sized messages up front
16 fn put_length_prefixedrust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/impl#[`Vec<u8>`][PgBufMutExt]put_length_prefixed().<F>(&mut self, write_contents: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>
17 where
18 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>,
19 {
20 // reserve space to write the prefixed length
21 let offset = self.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
22 self.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&[0; 4]);
23
24 // write the main body of the message
25 let write_result = write_contents(self);
26
27 let size_result = write_result.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|_| {
28 let size = 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;
29 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)
30 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!("message size out of range for protocol: {size}"))
31 });
32
33 match size_result {
34 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(size) => {
35 // now calculate the size of what we wrote and set the length value
36 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().(&size.to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]to_be_bytes().());
37 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
38 }
39 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
40 // Put the buffer back to where it was.
41 self.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(offset);
42 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)
43 }
44 }
45 }
46
47 // writes a statement name by ID
48 #[inline]
49 fn put_statement_namerust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/impl#[`Vec<u8>`][PgBufMutExt]put_statement_name().(&mut self, id: StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#) {
50 id.put_name_with_nulrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[StatementId]put_name_with_nul().(self);
51 }
52
53 // writes a portal name by ID
54 #[inline]
55 fn put_portal_namerust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/impl#[`Vec<u8>`][PgBufMutExt]put_portal_name().(&mut self, id: PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#) {
56 id.put_name_with_nulrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[PortalId]put_name_with_nul().(self);
57 }
58 }