Struct std::old_io::BufferedWriterUnstable
[-] [+]
[src]
pub struct BufferedWriter<W> { // some fields omitted }
Wraps a Writer and buffers output to it
It can be excessively inefficient to work directly with a Writer
. For
example, every call to write
on TcpStream
results in a system call. A
BufferedWriter
keeps an in memory buffer of data and writes it to the
underlying Writer
in large, infrequent batches.
This writer will be flushed when it is dropped.
Example
fn main() { use std::old_io::{BufferedWriter, File}; let file = File::create(&Path::new("message.txt")).unwrap(); let mut writer = BufferedWriter::new(file); writer.write_str("hello, world").unwrap(); writer.flush().unwrap(); }use std::old_io::{BufferedWriter, File}; let file = File::create(&Path::new("message.txt")).unwrap(); let mut writer = BufferedWriter::new(file); writer.write_str("hello, world").unwrap(); writer.flush().unwrap();
Methods
impl<W: Writer> BufferedWriter<W>
fn with_capacity(cap: usize, inner: W) -> BufferedWriter<W>
Creates a new BufferedWriter
with the specified buffer capacity
fn new(inner: W) -> BufferedWriter<W>
Creates a new BufferedWriter
with a default buffer capacity
fn get_ref(&self) -> &W
Gets a reference to the underlying writer.
fn get_mut(&mut self) -> &mut W
Gets a mutable reference to the underlying write.
Warning
It is inadvisable to directly read from the underlying writer.
fn into_inner(self) -> W
Unwraps this BufferedWriter
, returning the underlying writer.
The buffer is flushed before returning the writer.