Struct vmap::io::InfiniteRing[][src]

pub struct InfiniteRing { /* fields omitted */ }

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]

impl Debug for InfiniteRing[src]

impl Drop for InfiniteRing[src]

impl Read for InfiniteRing[src]

impl SeqRead for InfiniteRing[src]

impl SeqWrite for InfiniteRing[src]

impl Write for InfiniteRing[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.