pub struct RecvStream<R = OwnedReadHalf> { /* private fields */ }Expand description
Framed receive stream for length-delimited messages.
Generic over the underlying reader type - works with TCP, TLS, or any AsyncRead.
Implementations§
Source§impl<R: AsyncRead + Unpin> RecvStream<R>
impl<R: AsyncRead + Unpin> RecvStream<R>
pub fn new(stream: R) -> Self
pub async fn recv_object<T: DeserializeOwned>(&mut self) -> Result<Option<T>>
Sourcepub async fn copy_to<W: AsyncWrite + Unpin>(
&mut self,
writer: &mut W,
) -> Result<u64>
pub async fn copy_to<W: AsyncWrite + Unpin>( &mut self, writer: &mut W, ) -> Result<u64>
Copies data to a writer using the default buffer size (8 KiB).
For better performance with large files, use Self::copy_to_buffered instead.
Sourcepub async fn copy_to_buffered<W: AsyncWrite + Unpin>(
&mut self,
writer: &mut W,
buffer_size: usize,
) -> Result<u64>
pub async fn copy_to_buffered<W: AsyncWrite + Unpin>( &mut self, writer: &mut W, buffer_size: usize, ) -> Result<u64>
Copies data to a writer using a custom buffer size.
Uses a buffered reader around the TCP stream with the specified capacity.
This avoids the default 8 KiB buffer in tokio::io::copy and can significantly
improve throughput on high-bandwidth networks.
Sourcepub async fn copy_exact_to_buffered<W: AsyncWrite + Unpin>(
&mut self,
writer: &mut W,
size: u64,
buffer_size: usize,
) -> Result<u64>
pub async fn copy_exact_to_buffered<W: AsyncWrite + Unpin>( &mut self, writer: &mut W, size: u64, buffer_size: usize, ) -> Result<u64>
Copies exactly size bytes to a writer using a custom buffer size.
Unlike Self::copy_to_buffered, this does NOT read until EOF. It reads
exactly the specified number of bytes, leaving the stream open for
reading subsequent messages.
pub async fn close(&mut self)
Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for RecvStream<R>where
R: Freeze,
impl<R> RefUnwindSafe for RecvStream<R>where
R: RefUnwindSafe,
impl<R> Send for RecvStream<R>where
R: Send,
impl<R> Sync for RecvStream<R>where
R: Sync,
impl<R> Unpin for RecvStream<R>where
R: Unpin,
impl<R> UnsafeUnpin for RecvStream<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for RecvStream<R>where
R: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request