Struct vmap::io::InfiniteRing [−][src]
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
impl InfiniteRing
[src]
pub fn new(hint: usize) -> Result<Self>
[src]
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
impl BufRead for InfiniteRing
[src]
fn fill_buf(&mut self) -> Result<&[u8]>
[src]
fn consume(&mut self, len: usize)
[src]
pub fn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
1.0.0[src]
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
pub fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
pub fn split(self, byte: u8) -> Split<Self>
1.0.0[src]
pub fn lines(self) -> Lines<Self>
1.0.0[src]
impl Debug for InfiniteRing
[src]
impl Drop for InfiniteRing
[src]
impl Read for InfiniteRing
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
pub fn read_vectored(
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
1.36.0[src]
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
pub fn is_read_vectored(&self) -> bool
[src]
pub unsafe fn initializer(&self) -> Initializer
[src]
pub fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
1.0.0[src]
pub fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
pub fn bytes(self) -> Bytes<Self>
1.0.0[src]
pub fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
pub fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
impl SeqRead for InfiniteRing
[src]
fn as_read_ptr(&self) -> *const u8
[src]
fn read_offset(&self) -> usize
[src]
fn read_len(&self) -> usize
[src]
fn is_empty(&self) -> bool
[src]
fn as_read_slice(&self, max: usize) -> &[u8]ⓘ
[src]
fn read_from(&mut self, into: &mut [u8]) -> Result<usize>
[src]
impl SeqWrite for InfiniteRing
[src]
fn as_write_ptr(&mut self) -> *mut u8
[src]
fn write_offset(&self) -> usize
[src]
fn write_len(&self) -> usize
[src]
fn write_capacity(&self) -> usize
[src]
fn feed(&mut self, len: usize)
[src]
fn is_full(&self) -> bool
[src]
fn as_write_slice(&mut self, max: usize) -> &mut [u8]ⓘ
[src]
fn write_into(&mut self, from: &[u8]) -> Result<usize>
[src]
impl Write for InfiniteRing
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn write_all(&mut self, buf: &[u8]) -> Result<()>
[src]
fn flush(&mut self) -> Result<()>
[src]
pub fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>
1.36.0[src]
pub fn is_write_vectored(&self) -> bool
[src]
pub fn write_all_vectored(
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
[src]
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
1.0.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Auto Trait Implementations
impl RefUnwindSafe for InfiniteRing
[src]
impl !Send for InfiniteRing
[src]
impl !Sync for InfiniteRing
[src]
impl Unpin for InfiniteRing
[src]
impl UnwindSafe for InfiniteRing
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,