pub struct BufReader<R> { /* private fields */ }Expand description
The BufReader struct adds buffering to any reader.
It can be excessively inefficient to work directly with a Read instance.
For example, every call to read on TcpStream results in a system call.
A BufReader performs large, infrequent reads on the underlying Read
and maintains an in-memory buffer of the results.
§Examples
use std::io::prelude::*;
use std::fs::File;
use seek_bufread::BufReader;
let mut f = try!(File::open("log.txt"));
let mut reader = BufReader::new(f);
let mut line = String::new();
let len = try!(reader.read_line(&mut line));
println!("First line is {} bytes long", len);Implementations§
Source§impl<R> BufReader<R>
impl<R> BufReader<R>
Sourcepub fn new(inner: R) -> BufReader<R> ⓘ
pub fn new(inner: R) -> BufReader<R> ⓘ
Creates a new BufReader with a default buffer capacity (8192 bytes).
§Examples
use std::fs::File;
use seek_bufread::BufReader;
let mut f = try!(File::open("log.txt"));
let mut reader = BufReader::new(f);Examples found in repository?
8fn main() {
9 let ioreg = Command::new("ioreg")
10 .arg("-c")
11 .arg("IOUSB")
12 .arg("-a")
13 .output()
14 .unwrap();
15 let input = BufReader::new(Cursor::new(ioreg.stdout));
16
17 let stdout = OpenOptions::new()
18 .write(true)
19 .open(Path::new("/dev/stdout"))
20 .unwrap();
21
22 let output = BufWriter::new(stdout);
23
24 json::transcode_from_xml_reader(input, output)
25}Sourcepub fn with_capacity(cap: usize, inner: R) -> BufReader<R> ⓘ
pub fn with_capacity(cap: usize, inner: R) -> BufReader<R> ⓘ
Creates a new BufReader with the specified buffer capacity.
§Examples
Creating a buffer with ten bytes of capacity:
use std::fs::File;
use seek_bufread::BufReader;
let mut f = try!(File::open("log.txt"));
let mut reader = BufReader::with_capacity(10, f);Sourcepub fn available(&self) -> usize
pub fn available(&self) -> usize
Returns the current number of remaining bytes available in the buffer.
Sourcepub fn into_inner(self) -> Result<R, Error>
pub fn into_inner(self) -> Result<R, Error>
Consumes self, synchronizes the inner reader position and returns the inner reader.
Trait Implementations§
Source§impl<R> BufRead for BufReader<R>where
R: Read,
impl<R> BufRead for BufReader<R>where
R: Read,
Source§fn fill_buf(&mut self) -> Result<&[u8], Error>
fn fill_buf(&mut self) -> Result<&[u8], Error>
Read methods, if empty. Read moreSource§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amount of additional bytes from the internal buffer as having been read.
Subsequent calls to read only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA byte) is reached, and append
them to the provided String buffer. Read moreSource§impl<R> Read for BufReader<R>where
R: Read,
impl<R> Read for BufReader<R>where
R: Read,
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Reads the next available bytes from buffer or inner stream. Doesn’t guarantee the whole buffer is filled. Returns number of read bytes.
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read moreSource§impl<R> Seek for BufReader<R>
impl<R> Seek for BufReader<R>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
Seek to an offset, in bytes, in the buffer or the underlying reader.
The position used for seeking with SeekFrom::Current(_) is the
current position of the underlying reader plus the current position
in the internal buffer.
Calling .unwrap() immediately after a seek doesn’t guarantee
the underlying reader at the same position!
See std::io::Seek for more details.
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)