Struct vmap::io::InfiniteRing
source · [−]pub struct InfiniteRing { /* private fields */ }
Expand description
Fixed-size lossy read/write buffer with sequential address mapping.
This uses a circular address mapping scheme. That is, for any buffer of
size N
, the pointer address range of 0..N
maps to the same physical
memory as the range N..2*N
. This guarantees that the entire read or
write range may be addressed as a single sequence of bytes.
Unlike the Ring
, writes to this type may evict
bytes from the read side of the queue. The writeable size is always equal
to the overall capacity of the buffer.
Examples
use vmap::io::{InfiniteRing, SeqRead, SeqWrite};
use std::io::{BufRead, Read, Write};
let mut buf = InfiniteRing::new(4000).unwrap();
let mut i = 1;
let mut total = 0;
while total < buf.write_capacity() {
let tmp = format!("this is test line {}\n", i);
write!(buf, "{}", tmp);
total += tmp.len();
i += 1;
}
// skip over the overwritten tail
buf.consume(20 - buf.read_offset());
// read the next line
let mut line = String::new();
let len = buf.read_line(&mut line)?;
assert_eq!(len, 20);
assert_eq!(&line[line.len()-20..], "this is test line 2\n");
Implementations
sourceimpl InfiniteRing
impl InfiniteRing
sourcepub fn new(hint: usize) -> Result<Self>
pub fn new(hint: usize) -> Result<Self>
Constructs a new ring buffer instance.
The hint is a minimum size for the buffer. This size will be rounded up to the nearest page size for the actual capacity. The allocation will occupy double the space in the virtual memory table, but the physical memory usage will remain at the desired capacity.
Trait Implementations
sourceimpl BufRead for InfiniteRing
impl BufRead for InfiniteRing
sourcefn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
sourcefn consume(&mut self, len: usize)
fn consume(&mut self, len: usize)
Tells this buffer that amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read more
sourcefn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)Check if the underlying Read
has any data left to be read. Read more
1.0.0 · sourcefn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
fn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
Read all bytes into buf
until the delimiter byte
or EOF is reached. Read more
1.0.0 · sourcefn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until a newline (the 0xA
byte) is reached, and append
them to the provided buffer. You do not need to clear the buffer before
appending. Read more
sourceimpl Debug for InfiniteRing
impl Debug for InfiniteRing
sourceimpl Drop for InfiniteRing
impl Drop for InfiniteRing
sourceimpl Read for InfiniteRing
impl Read for InfiniteRing
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like read
, except that it reads into a slice of buffers. Read more
sourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into buf
. Read more
1.0.0 · sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until EOF in this source, appending them to buf
. Read more
1.6.0 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill buf
. Read more
sourcefn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Pull some bytes from this source into the specified buffer. Read more
sourcefn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Read the exact number of bytes required to fill buf
. Read more
1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
sourceimpl SeqRead for InfiniteRing
impl SeqRead for InfiniteRing
sourcefn as_read_ptr(&self) -> *const u8
fn as_read_ptr(&self) -> *const u8
Get the mapped readable pointer without any offset.
sourcefn read_offset(&self) -> usize
fn read_offset(&self) -> usize
Get the offset from the read pointer for the current read position.
sourceimpl SeqWrite for InfiniteRing
impl SeqWrite for InfiniteRing
sourcefn as_write_ptr(&mut self) -> *mut u8
fn as_write_ptr(&mut self) -> *mut u8
Get the mapped writable pointer without any offset.
sourcefn write_offset(&self) -> usize
fn write_offset(&self) -> usize
Get the offset from the write pointer for the current read position.
sourcefn write_len(&self) -> usize
fn write_len(&self) -> usize
Get the total number of bytes that may be written after the current write offset.
sourcefn write_capacity(&self) -> usize
fn write_capacity(&self) -> usize
Gets the number of bytes that the buffer has currently allocated space for.
sourcefn feed(&mut self, len: usize)
fn feed(&mut self, len: usize)
Bump the write offset after writing into the writable slice. Read more
sourceimpl Write for InfiniteRing
impl Write for InfiniteRing
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Attempts to write an entire buffer into this writer. Read more
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations
impl RefUnwindSafe for InfiniteRing
impl !Send for InfiniteRing
impl !Sync for InfiniteRing
impl Unpin for InfiniteRing
impl UnwindSafe for InfiniteRing
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more