| 1 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::errorrust-analyzer cargo sqlx-core 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 2 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::netrust-analyzer cargo sqlx-core 0.8.3 net/::Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#; |
| 3 | use bytesrust-analyzer cargo bytes 1.12.1 crate/::BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#; |
| 4 | 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/::ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/}; |
| 6 | |
| 7 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::iorust-analyzer cargo sqlx-core 0.8.3 io/::{AsyncReadrust-analyzer cargo tokio 1.53.1 io/async_read/AsyncRead#, AsyncReadExtrust-analyzer cargo tokio 1.53.1 io/util/async_read_ext/AsyncReadExt#, ProtocolDecoderust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#, ProtocolEncoderust-analyzer cargo sqlx-core 0.8.3 io/encode/ProtocolEncode#}; |
| 8 | |
| 9 | // Tokio, async-std, and std all use this as the default capacity for their buffered I/O. |
| 10 | const DEFAULT_BUF_SIZErust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/DEFAULT_BUF_SIZE.: usize = 8192; |
| 11 | |
| 12 | pub struct BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#<S> { |
| 13 | socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket.: S, |
| 14 | write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf.: WriteBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#, |
| 15 | read_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#read_buf.: ReadBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#, |
| 16 | } |
| 17 | |
| 18 | pub struct WriteBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer# { |
| 19 | bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 20 | bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written.: usize, |
| 21 | bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed.: usize, |
| 22 | } |
| 23 | |
| 24 | pub struct ReadBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer# { |
| 25 | readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#read.: BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#, |
| 26 | availablerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#available.: BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#, |
| 27 | } |
| 28 | |
| 29 | impl<S: Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#> BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#<S> { |
| 30 | pub fn newrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]new().(socket: S) -> Selfrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`] |
| 31 | where |
| 32 | S: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 33 | { |
| 34 | BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket# { |
| 35 | socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket., |
| 36 | write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf.: WriteBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer# { |
| 37 | bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(DEFAULT_BUF_SIZErust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/DEFAULT_BUF_SIZE.), |
| 38 | bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written.: 0, |
| 39 | bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed.: 0, |
| 40 | }, |
| 41 | read_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#read_buf.: ReadBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer# { |
| 42 | readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#read.: BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#::newrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]new().(), |
| 43 | availablerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#available.: BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#::with_capacityrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]with_capacity().(DEFAULT_BUF_SIZErust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/DEFAULT_BUF_SIZE.), |
| 44 | }, |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | pub async fn read_bufferedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]read_buffered().(&mut self, len: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 49 | self.try_readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]try_read().(|buf| { |
| 50 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(if buf.lenrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().len { |
| 51 | ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Continuerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Continue#(len) |
| 52 | } else { |
| 53 | ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Breakrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Break#(buf.split_torust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]split_to().(len)) |
| 54 | }) |
| 55 | }) |
| 56 | .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(). |
| 57 | } |
| 58 | |
| 59 | /// Retryable read operation. |
| 60 | /// |
| 61 | /// The callback should check the contents of the buffer passed to it and either: |
| 62 | /// |
| 63 | /// * Remove a full message from the buffer and return [`ControlFlow::Break`], or: |
| 64 | /// * Return [`ControlFlow::Continue`] with the expected _total_ length of the buffer, |
| 65 | /// _without_ modifying it. |
| 66 | /// |
| 67 | /// Cancel-safe as long as the callback does not modify the passed `BytesMut` |
| 68 | /// before returning [`ControlFlow::Continue`]. |
| 69 | pub async fn try_readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]try_read().<F, R>(&mut self, mut try_read: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<R, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> |
| 70 | where |
| 71 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#<R, usize>, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>, |
| 72 | { |
| 73 | loop { |
| 74 | let read_len = match try_read(&mut self.read_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#read_buf..readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#read.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 75 | ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Continuerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Continue#(read_len) => read_len, |
| 76 | ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Breakrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Break#(ret) => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ret), |
| 77 | }; |
| 78 | |
| 79 | self.read_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#read_buf..readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[ReadBuffer]read().(read_len, &mut self.socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket.).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().; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | pub fn write_bufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]write_buffer().(&self) -> &WriteBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer# { |
| 84 | &self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf. |
| 85 | } |
| 86 | |
| 87 | pub fn write_buffer_mutrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]write_buffer_mut().(&mut self) -> &mut WriteBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer# { |
| 88 | &mut self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf. |
| 89 | } |
| 90 | |
| 91 | pub async fn readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]read().<'de, T>(&mut self, byte_len: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> |
| 92 | where |
| 93 | T: ProtocolDecoderust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#<'de, ()>, |
| 94 | { |
| 95 | self.read_withrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]read_with().(byte_len, ()).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(). |
| 96 | } |
| 97 | |
| 98 | pub async fn read_withrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]read_with().<'de, T, C>(&mut self, byte_len: usize, context: C) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> |
| 99 | where |
| 100 | T: ProtocolDecoderust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#<'de, C>, |
| 101 | { |
| 102 | T::decode_withrust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#decode_with().(self.read_bufferedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]read_buffered().(byte_len).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()..freezerust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]freeze().(), context) |
| 103 | } |
| 104 | |
| 105 | #[inline(always)] |
| 106 | pub fn writerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]write().<'en, T>(&mut self, value: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> |
| 107 | where |
| 108 | T: ProtocolEncoderust-analyzer cargo sqlx-core 0.8.3 io/encode/ProtocolEncode#<'en, ()>, |
| 109 | { |
| 110 | self.write_withrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]write_with().(value, ()) |
| 111 | } |
| 112 | |
| 113 | #[inline(always)] |
| 114 | pub fn write_withrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]write_with().<'en, T, C>(&mut self, value: T, context: C) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> |
| 115 | where |
| 116 | T: ProtocolEncoderust-analyzer cargo sqlx-core 0.8.3 io/encode/ProtocolEncode#<'en, C>, |
| 117 | { |
| 118 | value.encode_withrust-analyzer cargo sqlx-core 0.8.3 io/encode/ProtocolEncode#encode_with().(self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..buf_mutrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]buf_mut().(), context)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 119 | self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. = self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 120 | self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..sanity_checkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]sanity_check().(); |
| 121 | |
| 122 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 123 | } |
| 124 | |
| 125 | pub async fn flushrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 126 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..is_emptyrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]is_empty().() { |
| 127 | let written = self.socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket..writerust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#write().(self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..getrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]get().()).rust-analyzer cargo sqlx-core 0.8.3 net/socket/impl#[`Write<'a, S>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 net/socket/impl#[`Write<'a, S>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 128 | self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..consumerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]consume().(written); |
| 129 | self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..sanity_checkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]sanity_check().(); |
| 130 | } |
| 131 | |
| 132 | self.socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket..flushrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#flush().().rust-analyzer cargo sqlx-core 0.8.3 net/socket/impl#[`Flush<'a, S>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 net/socket/impl#[`Flush<'a, S>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 133 | |
| 134 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 135 | } |
| 136 | |
| 137 | pub async fn shutdownrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]shutdown().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 138 | self.flushrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]flush().().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().; |
| 139 | self.socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket..shutdownrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#shutdown().().rust-analyzer cargo sqlx-core 0.8.3 net/socket/impl#[`Shutdown<'a, S>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 net/socket/impl#[`Shutdown<'a, S>`][Future]poll(). |
| 140 | } |
| 141 | |
| 142 | pub fn shrink_buffersrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]shrink_buffers().(&mut self) { |
| 143 | // Won't drop data still in the buffer. |
| 144 | self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf..shrinkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]shrink().(); |
| 145 | self.read_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#read_buf..shrinkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[ReadBuffer]shrink().(); |
| 146 | } |
| 147 | |
| 148 | pub fn into_innerrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]into_inner().(self) -> S { |
| 149 | self.socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket. |
| 150 | } |
| 151 | |
| 152 | pub fn boxedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]boxed().(self) -> BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#>> { |
| 153 | BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket# { |
| 154 | socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket.: 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().(self.socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#socket.), |
| 155 | write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf.: self.write_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#write_buf., |
| 156 | read_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#read_buf.: self.read_bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#read_buf., |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | impl WriteBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer# { |
| 162 | fn sanity_checkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]sanity_check().(&self) { |
| 163 | assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(), 0); |
| 164 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. <= self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 165 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed. <= self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written.); |
| 166 | } |
| 167 | |
| 168 | pub fn buf_mutrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]buf_mut().(&mut self) -> &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 169 | self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written.); |
| 170 | self.sanity_checkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]sanity_check().(); |
| 171 | &mut self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf. |
| 172 | } |
| 173 | |
| 174 | pub fn init_remaining_mutrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]init_remaining_mut().(&mut self) -> &mut [u8] { |
| 175 | self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..resizerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]resize().(self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(), 0); |
| 176 | self.sanity_checkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]sanity_check().(); |
| 177 | &mut self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 178 | } |
| 179 | |
| 180 | pub fn put_slicerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]put_slice().(&mut self, slice: &[u8]) { |
| 181 | // If we already have an initialized area that can fit the slice, |
| 182 | // don't change `self.buf.len()` |
| 183 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dest) = self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) { |
| 184 | dest.copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(slice); |
| 185 | } else { |
| 186 | self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written.); |
| 187 | self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(slice); |
| 188 | } |
| 189 | self.advancerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]advance().(slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 190 | self.sanity_checkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]sanity_check().(); |
| 191 | } |
| 192 | |
| 193 | pub fn advancerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]advance().(&mut self, amt: usize) { |
| 194 | let new_bytes_written = self |
| 195 | .bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. |
| 196 | .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(amt) |
| 197 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("self.bytes_written + amt overflowed"); |
| 198 | |
| 199 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(new_bytes_written <= self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 200 | |
| 201 | self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. = new_bytes_written; |
| 202 | |
| 203 | self.sanity_checkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]sanity_check().(); |
| 204 | } |
| 205 | |
| 206 | /// Read into the buffer from `source`, returning the number of bytes read. |
| 207 | /// |
| 208 | /// The buffer is automatically advanced by the number of bytes read. |
| 209 | pub async fn read_fromrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]read_from().(&mut self, mut source: impl AsyncReadrust-analyzer cargo tokio 1.53.1 io/async_read/AsyncRead# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 210 | let read = match () { |
| 211 | // Tokio lets us read into the buffer without zeroing first |
| 212 | #[cfg(feature = "_rt-tokio")] |
| 213 | _ => source.read_bufrust-analyzer cargo tokio 1.53.1 io/util/async_read_ext/AsyncReadExt#read_buf().(self.buf_mutrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]buf_mut().()).rust-analyzer cargo tokio 1.53.1 io/util/read_buf/impl#[`ReadBuf<'_, R, B>`][Future]poll().awaitrust-analyzer cargo tokio 1.53.1 io/util/read_buf/impl#[`ReadBuf<'_, R, B>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 214 | #[cfg(not(feature = "_rt-tokio"))] |
| 215 | _ => source.read(self.init_remaining_mut()).await?, |
| 216 | }; |
| 217 | |
| 218 | if read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 219 | self.advancerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]advance().(read); |
| 220 | } |
| 221 | |
| 222 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read) |
| 223 | } |
| 224 | |
| 225 | pub fn is_emptyrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]is_empty().(&self) -> bool { |
| 226 | self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. |
| 227 | } |
| 228 | |
| 229 | pub fn is_fullrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]is_full().(&self) -> bool { |
| 230 | self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 231 | } |
| 232 | |
| 233 | pub fn getrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]get().(&self) -> &[u8] { |
| 234 | &self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 235 | } |
| 236 | |
| 237 | pub fn get_mutrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]get_mut().(&mut self) -> &mut [u8] { |
| 238 | &mut self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 239 | } |
| 240 | |
| 241 | pub fn shrinkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]shrink().(&mut self) { |
| 242 | if self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 243 | // Move any data that remains to be flushed to the beginning of the buffer, |
| 244 | // if necessary. |
| 245 | self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf. |
| 246 | .copy_withinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_within().(self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written., 0); |
| 247 | self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed.; |
| 248 | self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed. = 0 |
| 249 | } |
| 250 | |
| 251 | // Drop excess capacity. |
| 252 | self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf. |
| 253 | .truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written., DEFAULT_BUF_SIZErust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/DEFAULT_BUF_SIZE.)); |
| 254 | self.bufrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#buf..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 255 | } |
| 256 | |
| 257 | fn consumerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]consume().(&mut self, amt: usize) { |
| 258 | let new_bytes_flushed = self |
| 259 | .bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed. |
| 260 | .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(amt) |
| 261 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("self.bytes_flushed + amt overflowed"); |
| 262 | |
| 263 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(new_bytes_flushed <= self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written.); |
| 264 | |
| 265 | self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed. = new_bytes_flushed; |
| 266 | |
| 267 | if self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. { |
| 268 | // Reset cursors to zero if we've consumed the whole buffer |
| 269 | self.bytes_flushedrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_flushed. = 0; |
| 270 | self.bytes_writtenrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/WriteBuffer#bytes_written. = 0; |
| 271 | } |
| 272 | |
| 273 | self.sanity_checkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[WriteBuffer]sanity_check().(); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | impl ReadBufferrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer# { |
| 278 | async fn readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[ReadBuffer]read().(&mut self, len: usize, socket: &mut impl Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 279 | // Because of how `BytesMut` works, we should only be shifting capacity back and forth |
| 280 | // between `read` and `available` unless we have to read an oversize message. |
| 281 | while self.readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#read..lenrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().len { |
| 282 | self.reserverust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[ReadBuffer]reserve().(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().self.readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#read..lenrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]len().()); |
| 283 | |
| 284 | let read = socket.readrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#read().(&mut self.availablerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#available.).rust-analyzer cargo sqlx-core 0.8.3 net/socket/impl#[`Read<'a, S, B>`][Future]poll().awaitrust-analyzer cargo sqlx-core 0.8.3 net/socket/impl#[`Read<'a, S, B>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 285 | |
| 286 | if read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 287 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 288 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof#, |
| 289 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 290 | "expected to read {} bytes, got {} bytes at EOF", |
| 291 | len, |
| 292 | self.readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#read..lenrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]len().() |
| 293 | ), |
| 294 | )); |
| 295 | } |
| 296 | |
| 297 | self.advancerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[ReadBuffer]advance().(read); |
| 298 | } |
| 299 | |
| 300 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 301 | } |
| 302 | |
| 303 | fn reserverust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[ReadBuffer]reserve().(&mut self, amt: usize) { |
| 304 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(additional) = amt.checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_sub().(self.availablerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#available..capacityrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]capacity().()) { |
| 305 | self.availablerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#available..reserverust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]reserve().(additional); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | fn advancerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[ReadBuffer]advance().(&mut self, amt: usize) { |
| 310 | self.readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#read..unsplitrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]unsplit().(self.availablerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#available..split_torust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]split_to().(amt)); |
| 311 | } |
| 312 | |
| 313 | fn shrinkrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[ReadBuffer]shrink().(&mut self) { |
| 314 | if self.availablerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#available..capacityrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]capacity().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().DEFAULT_BUF_SIZErust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/DEFAULT_BUF_SIZE. { |
| 315 | // `BytesMut` doesn't have a way to shrink its capacity, |
| 316 | // but we only use `available` for spare capacity anyway so we can just replace it. |
| 317 | // |
| 318 | // If `self.read` still contains data on the next call to `advance` then this might |
| 319 | // force a memcpy as they'll no longer be pointing to the same allocation, |
| 320 | // but that's kind of unavoidable. |
| 321 | // |
| 322 | // The `async-std` impl of `Socket` will also need to re-zero the buffer, |
| 323 | // but that's also kind of unavoidable. |
| 324 | // |
| 325 | // We should be warning the user not to call this often. |
| 326 | self.availablerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/ReadBuffer#available. = BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#::with_capacityrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]with_capacity().(DEFAULT_BUF_SIZErust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/DEFAULT_BUF_SIZE.); |
| 327 | } |
| 328 | } |
| 329 | } |