Struct bevy_internal::tasks::futures_lite::io::BufWriter
source · pub struct BufWriter<W> { /* private fields */ }
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§
source§impl<W> BufWriter<W>where
W: AsyncWrite,
impl<W> BufWriter<W>where
W: AsyncWrite,
sourcepub fn new(inner: W) -> BufWriter<W>
pub fn new(inner: W) -> BufWriter<W>
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);
sourcepub 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);
sourcepub fn get_ref(&self) -> &W
pub fn get_ref(&self) -> &W
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();
sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
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();
sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Unwraps 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]);
Trait Implementations§
source§impl<W> AsyncWrite for BufWriter<W>where
W: AsyncWrite,
impl<W> AsyncWrite for BufWriter<W>where
W: AsyncWrite,
source§fn poll_write(
self: Pin<&mut BufWriter<W>>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut BufWriter<W>>, cx: &mut Context<'_>, buf: &[u8] ) -> Poll<Result<usize, Error>>
buf
into the object. Read moresource§fn poll_flush(
self: Pin<&mut BufWriter<W>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut BufWriter<W>>, cx: &mut Context<'_> ) -> Poll<Result<(), Error>>
impl<'__pin, W> Unpin for BufWriter<W>where
__Origin<'__pin, W>: Unpin,
Auto Trait Implementations§
impl<W> RefUnwindSafe for BufWriter<W>where
W: RefUnwindSafe,
impl<W> Send for BufWriter<W>where
W: Send,
impl<W> Sync for BufWriter<W>where
W: Sync,
impl<W> UnwindSafe for BufWriter<W>where
W: UnwindSafe,
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.source§impl<S> AsyncSeekExt for S
impl<S> AsyncSeekExt for S
source§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> ⓘwhere
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> ⓘwhere
Self: Unpin,
source§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self> ⓘwhere
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self> ⓘwhere
Self: Unpin,
source§fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> ⓘwhere
Self: Unpin,
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> ⓘwhere
Self: Unpin,
source§fn flush(&mut self) -> FlushFuture<'_, Self> ⓘwhere
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self> ⓘwhere
Self: Unpin,
source§fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
dyn AsyncWrite + Send + 'a
. Read moresource§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
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.