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§
source§impl 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§
source§impl BufRead for InfiniteRing
impl BufRead for InfiniteRing
source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
source§fn consume(&mut self, len: usize)
fn consume(&mut self, len: usize)
amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to 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
has any data left to be read. Read moresource§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
bufread_skip_until
)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 Debug for InfiniteRing
impl Debug for InfiniteRing
source§impl Drop for InfiniteRing
impl Drop for InfiniteRing
source§impl Read for InfiniteRing
impl Read for InfiniteRing
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
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 SeqRead for InfiniteRing
impl SeqRead for InfiniteRing
source§fn as_read_ptr(&self) -> *const u8
fn as_read_ptr(&self) -> *const u8
source§fn read_offset(&self) -> usize
fn read_offset(&self) -> usize
source§impl SeqWrite for InfiniteRing
impl SeqWrite for InfiniteRing
source§fn as_write_ptr(&mut self) -> *mut u8
fn as_write_ptr(&mut self) -> *mut u8
source§fn write_offset(&self) -> usize
fn write_offset(&self) -> usize
source§fn write_len(&self) -> usize
fn write_len(&self) -> usize
source§fn write_capacity(&self) -> usize
fn write_capacity(&self) -> usize
source§fn feed(&mut self, len: usize)
fn feed(&mut self, len: usize)
source§impl Write for InfiniteRing
impl Write for InfiniteRing
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)