pub struct MessageReader { /* private fields */ }Expand description
Cancellation-safe backend message reader.
PostgreSQL backend messages span multiple read operations (5-byte header,
then a variable payload). A naive implementation using read_exact is
not cancellation-safe: if the future is dropped between reads (e.g. by
tokio::select! or tokio::time::timeout), bytes already pulled from the
underlying stream are lost and the next read mis-parses the wire stream.
MessageReader externalizes the partial-read state so it survives across
dropped futures. Each call to read uses one-shot
AsyncReadExt::read (which is cancel-safe) and accumulates progress
on self. If the returned future is dropped, no bytes are lost; the next
invocation resumes from where the previous one left off.
Implementations§
Source§impl MessageReader
impl MessageReader
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MessageReader
impl RefUnwindSafe for MessageReader
impl Send for MessageReader
impl Sync for MessageReader
impl Unpin for MessageReader
impl UnsafeUnpin for MessageReader
impl UnwindSafe for MessageReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more