Skip to main content

BufStream

Struct BufStream 

Source
pub struct BufStream<S> { /* private fields */ }
Expand description

A stream with a read buffer and a write buffer in front: a BufReader around a BufWriter.

Implementations§

Source§

impl<S> BufStream<S>

Source

pub fn new(stream: S) -> Self

Buffers of 8 KiB each way in front of stream.

Source

pub fn with_capacity(read: usize, write: usize, stream: S) -> Self

A read buffer of read bytes and a write buffer of write bytes in front of stream.

Source

pub fn get_ref(&self) -> &S

The stream inside.

Source

pub fn get_mut(&mut self) -> &mut S

The stream inside, to change.

Source

pub fn into_inner(self) -> S

The stream inside, taken back; the bytes buffered either way are lost.

Trait Implementations§

Source§

impl<S: AsyncRead + AsyncWrite + Unpin> AsyncBufRead for BufStream<S>

Source§

fn poll_fill_buf( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<&[u8]>>

Attempt to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Source§

fn consume(self: Pin<&mut Self>, amount: usize)

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Source§

impl<S: AsyncRead + AsyncWrite + Unpin> AsyncRead for BufStream<S>

Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into buf. Read more
§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Source§

impl<S: AsyncRead + AsyncWrite + Unpin> AsyncWrite for BufStream<S>

Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
Source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to close the object. Read more
Source§

impl<S: Debug> Debug for BufStream<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for BufStream<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for BufStream<S>
where S: RefUnwindSafe,

§

impl<S> Send for BufStream<S>
where S: Send,

§

impl<S> Sync for BufStream<S>
where S: Sync,

§

impl<S> Unpin for BufStream<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for BufStream<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for BufStream<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<R> AsyncBufReadExt for R
where R: AsyncBufRead + ?Sized,

Source§

fn read_until<'a>( &'a mut self, byte: u8, buf: &'a mut Vec<u8>, ) -> ReadUntil<'a, Self> ⓘ
where Self: Unpin,

Reads up to and including byte (or to the end), appending to buf; answers how many bytes it appended (0 at the end).
Source§

fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> ⓘ
where Self: Unpin,

Reads up to and including a newline (or to the end), appending to buf if what it read is UTF-8 (an InvalidData error and buf as it was otherwise); answers how many bytes it appended (0 at the end).
Source§

fn lines(self) -> Lines<Self>
where Self: Sized,

The lines, without their \n or \r\n, one by one through Lines::next_line.
Source§

fn split(self, byte: u8) -> Split<Self>
where Self: Sized,

The segments between bytes, without it, one by one through Split::next_segment.
Source§

fn fill_buf(&mut self) -> FillBuf<'_, Self> ⓘ
where Self: Unpin,

The reader’s buffer, filled if it was empty (empty at the end).
Source§

fn consume(&mut self, amount: usize)
where Self: Unpin,

Marks amount bytes of the buffer read.
Source§

impl<R> AsyncReadExt for R
where R: AsyncRead + ?Sized,

Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> ⓘ
where Self: Unpin,

Reads some bytes into buf, answering how many (0 at the end).
Source§

fn read_buf<'a, 'b>( &'a mut self, buf: &'a mut ReadBuf<'b>, ) -> ReadBufFuture<'a, 'b, Self> ⓘ
where Self: Unpin,

Reads some bytes into the unfilled part of buf and counts them filled, answering how many (0 at the end, or when buf is full).
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> ⓘ
where Self: Unpin,

Fills buf exactly, answering its length; an end of the stream first is an UnexpectedEof error.
Source§

fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self> ⓘ
where Self: Unpin,

Reads to the end of the stream, appending to buf; answers how many bytes it appended.
Source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String, ) -> ReadToString<'a, Self> ⓘ
where Self: Unpin,

Reads to the end of the stream, appending to buf if what it read is UTF-8 (an InvalidData error and buf as it was otherwise); answers how many bytes it appended.
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

A reader that ends after limit bytes of this one.
Source§

fn chain<R: AsyncRead>(self, next: R) -> Chain<Self, R>
where Self: Sized,

A reader that reads this one to its end, then next.
Source§

fn read_u8(&mut self) -> ReadNumber<'_, Self, u8, 1> ⓘ
where Self: Unpin,

Reads an unsigned byte (1 bytes, exactly).
Source§

fn read_i8(&mut self) -> ReadNumber<'_, Self, i8, 1> ⓘ
where Self: Unpin,

Reads a signed byte (1 bytes, exactly).
Source§

fn read_u16(&mut self) -> ReadNumber<'_, Self, u16, 2> ⓘ
where Self: Unpin,

Reads a big-endian u16 (2 bytes, exactly).
Source§

fn read_u16_le(&mut self) -> ReadNumber<'_, Self, u16, 2> ⓘ
where Self: Unpin,

Reads a little-endian u16 (2 bytes, exactly).
Source§

fn read_i16(&mut self) -> ReadNumber<'_, Self, i16, 2> ⓘ
where Self: Unpin,

Reads a big-endian i16 (2 bytes, exactly).
Source§

fn read_i16_le(&mut self) -> ReadNumber<'_, Self, i16, 2> ⓘ
where Self: Unpin,

Reads a little-endian i16 (2 bytes, exactly).
Source§

fn read_u32(&mut self) -> ReadNumber<'_, Self, u32, 4> ⓘ
where Self: Unpin,

Reads a big-endian u32 (4 bytes, exactly).
Source§

fn read_u32_le(&mut self) -> ReadNumber<'_, Self, u32, 4> ⓘ
where Self: Unpin,

Reads a little-endian u32 (4 bytes, exactly).
Source§

fn read_i32(&mut self) -> ReadNumber<'_, Self, i32, 4> ⓘ
where Self: Unpin,

Reads a big-endian i32 (4 bytes, exactly).
Source§

fn read_i32_le(&mut self) -> ReadNumber<'_, Self, i32, 4> ⓘ
where Self: Unpin,

Reads a little-endian i32 (4 bytes, exactly).
Source§

fn read_u64(&mut self) -> ReadNumber<'_, Self, u64, 8> ⓘ
where Self: Unpin,

Reads a big-endian u64 (8 bytes, exactly).
Source§

fn read_u64_le(&mut self) -> ReadNumber<'_, Self, u64, 8> ⓘ
where Self: Unpin,

Reads a little-endian u64 (8 bytes, exactly).
Source§

fn read_i64(&mut self) -> ReadNumber<'_, Self, i64, 8> ⓘ
where Self: Unpin,

Reads a big-endian i64 (8 bytes, exactly).
Source§

fn read_i64_le(&mut self) -> ReadNumber<'_, Self, i64, 8> ⓘ
where Self: Unpin,

Reads a little-endian i64 (8 bytes, exactly).
Source§

fn read_u128(&mut self) -> ReadNumber<'_, Self, u128, 16> ⓘ
where Self: Unpin,

Reads a big-endian u128 (16 bytes, exactly).
Source§

fn read_u128_le(&mut self) -> ReadNumber<'_, Self, u128, 16> ⓘ
where Self: Unpin,

Reads a little-endian u128 (16 bytes, exactly).
Source§

fn read_i128(&mut self) -> ReadNumber<'_, Self, i128, 16> ⓘ
where Self: Unpin,

Reads a big-endian i128 (16 bytes, exactly).
Source§

fn read_i128_le(&mut self) -> ReadNumber<'_, Self, i128, 16> ⓘ
where Self: Unpin,

Reads a little-endian i128 (16 bytes, exactly).
Source§

fn read_f32(&mut self) -> ReadNumber<'_, Self, f32, 4> ⓘ
where Self: Unpin,

Reads a big-endian f32 (4 bytes, exactly).
Source§

fn read_f32_le(&mut self) -> ReadNumber<'_, Self, f32, 4> ⓘ
where Self: Unpin,

Reads a little-endian f32 (4 bytes, exactly).
Source§

fn read_f64(&mut self) -> ReadNumber<'_, Self, f64, 8> ⓘ
where Self: Unpin,

Reads a big-endian f64 (8 bytes, exactly).
Source§

fn read_f64_le(&mut self) -> ReadNumber<'_, Self, f64, 8> ⓘ
where Self: Unpin,

Reads a little-endian f64 (8 bytes, exactly).
Source§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

Source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘ
where Self: Unpin,

Writes some of buf, answering how many bytes.
Source§

fn write_vectored<'a, 'b>( &'a mut self, bufs: &'a [IoSlice<'b>], ) -> WriteVectored<'a, 'b, Self> ⓘ
where Self: Unpin,

Writes some of the slices bufs, in order, answering how many bytes.
Source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> ⓘ
where Self: Unpin,

Writes all of buf; a writer that takes no more bytes is a WriteZero error.
Source§

fn flush(&mut self) -> Flush<'_, Self> ⓘ
where Self: Unpin,

Writes out what the writer holds back, down to its destination.
Source§

fn shutdown(&mut self) -> Shutdown<'_, Self> ⓘ
where Self: Unpin,

Flushes and closes the writing side (poll_close): a socket sends its end of stream, a pipe’s reader sees its end.
Source§

fn write_u8(&mut self, n: u8) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes an unsigned byte, all of its bytes.
Source§

fn write_i8(&mut self, n: i8) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a signed byte, all of its bytes.
Source§

fn write_u16(&mut self, n: u16) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian u16, all of its bytes.
Source§

fn write_u16_le(&mut self, n: u16) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian u16, all of its bytes.
Source§

fn write_i16(&mut self, n: i16) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian i16, all of its bytes.
Source§

fn write_i16_le(&mut self, n: i16) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian i16, all of its bytes.
Source§

fn write_u32(&mut self, n: u32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian u32, all of its bytes.
Source§

fn write_u32_le(&mut self, n: u32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian u32, all of its bytes.
Source§

fn write_i32(&mut self, n: i32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian i32, all of its bytes.
Source§

fn write_i32_le(&mut self, n: i32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian i32, all of its bytes.
Source§

fn write_u64(&mut self, n: u64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian u64, all of its bytes.
Source§

fn write_u64_le(&mut self, n: u64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian u64, all of its bytes.
Source§

fn write_i64(&mut self, n: i64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian i64, all of its bytes.
Source§

fn write_i64_le(&mut self, n: i64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian i64, all of its bytes.
Source§

fn write_u128(&mut self, n: u128) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian u128, all of its bytes.
Source§

fn write_u128_le(&mut self, n: u128) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian u128, all of its bytes.
Source§

fn write_i128(&mut self, n: i128) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian i128, all of its bytes.
Source§

fn write_i128_le(&mut self, n: i128) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian i128, all of its bytes.
Source§

fn write_f32(&mut self, n: f32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian f32, all of its bytes.
Source§

fn write_f32_le(&mut self, n: f32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian f32, all of its bytes.
Source§

fn write_f64(&mut self, n: f64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian f64, all of its bytes.
Source§

fn write_f64_le(&mut self, n: f64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian f64, all of its bytes.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.