Struct grafix_toolbox::uses::Async::io::BufWriter [−]
pub struct BufWriter<W> { /* fields omitted */ }Expand description
Adds buffering to a writer.
It can be excessively inefficient to work directly with something that implements
AsyncWrite. For example, every call to write() on a TCP
stream results in a system call. A BufWriter keeps an in-memory buffer of data and
writes it to the underlying writer in large, infrequent batches.
BufWriter can improve the speed of programs that make small and repeated writes to
the same file or networking socket. It does not help when writing very large amounts at
once, or writing just once or a few times. It also provides no advantage when writing to a
destination that is in memory, like a Vec<u8>.
Unlike std::io::BufWriter, this type does not write out the contents of its buffer when
it is dropped. Therefore, it is important that users explicitly flush the buffer before
dropping the BufWriter.
Examples
use futures_lite::io::{AsyncWriteExt, BufWriter}; let mut output = Vec::new(); let mut writer = BufWriter::new(&mut output); writer.write_all(b"hello").await?; writer.flush().await?;
Implementations
impl<W> BufWriter<W> where
W: AsyncWrite,
impl<W> BufWriter<W> where
W: AsyncWrite, Creates a buffered writer with the default buffer capacity.
The default capacity is currently 8 KB, but that may change in the future.
Examples
use futures_lite::io::BufWriter; let mut output = Vec::new(); let writer = BufWriter::new(&mut output);
pub fn with_capacity(capacity: usize, inner: W) -> BufWriter<W>
pub fn with_capacity(capacity: usize, inner: W) -> BufWriter<W>Creates a buffered writer with the specified buffer capacity.
Examples
use futures_lite::io::BufWriter; let mut output = Vec::new(); let writer = BufWriter::with_capacity(100, &mut output);
Gets a reference to the underlying writer.
Examples
use futures_lite::io::BufWriter; let mut output = Vec::new(); let writer = BufWriter::new(&mut output); let r = writer.get_ref();
Gets a mutable reference to the underlying writer.
It is not advisable to directly write to the underlying writer.
Examples
use futures_lite::io::BufWriter; let mut output = Vec::new(); let mut writer = BufWriter::new(&mut output); let r = writer.get_mut();
pub fn into_inner(self) -> W
pub fn into_inner(self) -> WUnwraps the buffered writer, returning the underlying writer.
Note that any leftover data in the internal buffer will be lost. If you don’t want to lose that data, flush the buffered writer before unwrapping it.
Examples
use futures_lite::io::{AsyncWriteExt, BufWriter}; let mut output = vec![1, 2, 3]; let mut writer = BufWriter::new(&mut output); writer.write_all(&[4]).await?; writer.flush().await?; assert_eq!(writer.into_inner(), &[1, 2, 3, 4]);
Returns a reference to the internal buffer.
Examples
use futures_lite::io::BufWriter; let mut output = Vec::new(); let writer = BufWriter::new(&mut output); // The internal buffer is empty until the first write request. assert_eq!(writer.buffer(), &[]);
Trait Implementations
impl<W> AsyncSeek for BufWriter<W> where
W: AsyncWrite + AsyncSeek,
impl<W> AsyncSeek for BufWriter<W> where
W: AsyncWrite + AsyncSeek, impl<W> AsyncWrite for BufWriter<W> where
W: AsyncWrite,
impl<W> AsyncWrite for BufWriter<W> where
W: AsyncWrite, impl<W> Debug for BufWriter<W> where
W: AsyncWrite + Debug,
impl<W> Debug for BufWriter<W> where
W: AsyncWrite + Debug, Auto Trait Implementations
impl<W> RefUnwindSafe for BufWriter<W> where
W: RefUnwindSafe, impl<W> UnwindSafe for BufWriter<W> where
W: UnwindSafe, Blanket Implementations
impl<S> AsyncSeekExt for S where
S: AsyncSeek + ?Sized,
impl<S> AsyncSeekExt for S where
S: AsyncSeek + ?Sized, fn seek(&mut self, pos: SeekFrom) -> SeekFuture<'_, Self>ⓘNotable traits for SeekFuture<'_, S>
impl<'_, S> Future for SeekFuture<'_, S> where
S: AsyncSeek + Unpin + ?Sized, type Output = Result<u64, Error>; where
Self: Unpin,
fn seek(&mut self, pos: SeekFrom) -> SeekFuture<'_, Self>ⓘNotable traits for SeekFuture<'_, S>
impl<'_, S> Future for SeekFuture<'_, S> where
S: AsyncSeek + Unpin + ?Sized, type Output = Result<u64, Error>; where
Self: Unpin, Seeks to a new position in a byte stream. Read more
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized, fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>ⓘNotable traits for WriteFuture<'_, W>
impl<'_, W> Future for WriteFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>ⓘNotable traits for WriteFuture<'_, W>
impl<'_, W> Future for WriteFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, Writes some bytes into the byte stream. Read more
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘNotable traits for WriteVectoredFuture<'_, W>
impl<'_, W> Future for WriteVectoredFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘNotable traits for WriteVectoredFuture<'_, W>
impl<'_, W> Future for WriteVectoredFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>ⓘNotable traits for WriteAllFuture<'_, W>
impl<'_, W> Future for WriteAllFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>ⓘNotable traits for WriteAllFuture<'_, W>
impl<'_, W> Future for WriteAllFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin, Writes an entire buffer into the byte stream. Read more
fn flush(&mut self) -> FlushFuture<'_, Self>ⓘNotable traits for FlushFuture<'_, W>
impl<'_, W> Future for FlushFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self>ⓘNotable traits for FlushFuture<'_, W>
impl<'_, W> Future for FlushFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin, Flushes the stream to ensure that all buffered contents reach their destination. Read more
fn close(&mut self) -> CloseFuture<'_, Self>ⓘNotable traits for CloseFuture<'_, W>
impl<'_, W> Future for CloseFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
fn close(&mut self) -> CloseFuture<'_, Self>ⓘNotable traits for CloseFuture<'_, W>
impl<'_, W> Future for CloseFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin, Closes the writer. Read more
Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. Read more
Mutably borrows from an owned value. Read more
type Output = T
type Output = TShould always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> boolChecks if self is actually part of its subset T (and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SSUse with care! Same as self.to_subset but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SPThe inclusion map: converts self to the equivalent element of its superset.
pub fn vzip(self) -> V