[−][src]Struct bra::GreedyBufReader
A buffered reader that greedily retains all memory read into a buffer.
Like std::io::BufReader
, it fetches bytes from the source in bulk to
reduce the number of actual reads. Moreover, it provides methods for
reading a byte or slice of bytes at an arbitrary position, reading as many
bytes as required to reach that position of the data stream, if they are
not in memory already. The position indices are always relative to the
position of the data source when it was passed to this construct via
new
or with_capacity
.
Methods
impl<R> GreedyBufReader<R> where
R: Read,
[src]
R: Read,
pub fn new(src: R) -> Self
[src]
Creates a new greedy buffered reader with the given byte source.
pub fn with_capacity(src: R, capacity: usize) -> Self
[src]
Creates a new greedy buffered reader with the given byte source and the specified buffer capacity.
The buffer will be able to read approximately capacity
bytes without
reallocating.
pub fn into_inner(self) -> R
[src]
Retrieves the internal reader, discarding the buffer in the process.
Note that any leftover data in the internal buffer is lost.
pub fn into_buffer(self) -> Vec<u8>
[src]
Retrieves the internal buffer in its current state, discarding the reader in the process.
pub fn get(&mut self, index: usize) -> IoResult<u8>
[src]
Fetches a single byte from the buffered data source.
pub fn slice<T>(&mut self, range: T) -> IoResult<&[u8]> where
T: Clone,
T: RangeBounds<usize>,
[src]
T: Clone,
T: RangeBounds<usize>,
Obtains a slice of bytes.
The range's end must be bound (e.g. 5..
is not supported).
Error
Returns an I/O error if the range is out of the boundaries
Panics
Panics if the range is not end bounded.
pub fn clear(&mut self)
[src]
Clears all memory of past reads, shrinking or freeing the buffer in the
process. The reader will behave as if freshly constructed, save for
already prefetched data, so that no bytes are lost. The following byte
being read becomes the byte at index #0
.
pub fn shrink_to_fit(&mut self)
[src]
Shrinks the internal buffer to minimal capacity.
Trait Implementations
impl<R> BufRead for GreedyBufReader<R> where
R: Read,
[src]
R: Read,
fn fill_buf(&mut self) -> IoResult<&[u8]>
[src]
fn consume(&mut self, amt: usize)
[src]
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
Read all bytes into buf
until the delimiter byte
or EOF is reached. Read more
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more
fn split(self, byte: u8) -> Split<Self>
1.0.0[src]
Returns an iterator over the contents of this reader split on the byte byte
. Read more
fn lines(self) -> Lines<Self>
1.0.0[src]
Returns an iterator over the lines of this reader. Read more
impl<R> Read for GreedyBufReader<R> where
R: Read,
[src]
R: Read,
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
[src]
unsafe fn initializer(&self) -> Initializer
[src]
read_initializer
)Determines if this Read
er can work with buffers of uninitialized memory. Read more
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
Read all bytes until EOF in this source, placing them into buf
. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
Read all bytes until EOF in this source, appending them to buf
. Read more
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
Read the exact number of bytes required to fill buf
. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Creates a "by reference" adaptor for this instance of Read
. Read more
fn bytes(self) -> Bytes<Self>
1.0.0[src]
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
Creates an adaptor which will chain this stream with another. Read more
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
Creates an adaptor which will read at most limit
bytes from it. Read more
Auto Trait Implementations
impl<R> Send for GreedyBufReader<R> where
R: Send,
R: Send,
impl<R> Sync for GreedyBufReader<R> where
R: Sync,
R: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,