[][src]Struct vmcircbuf::Buffer

pub struct Buffer { /* fields omitted */ }

A raw circular buffer of bytes. The buffer holds exactly size many bytes but it is presented as a size + wrap length slice where the last wrap many bytes overlap with the first wrap many bytes of the slice. This magic trick is performed with virtual memory, the same physical pages are mapped both at the start and at the end of the buffer.

Methods

impl Buffer[src]

pub fn page_size() -> Result<usize, Error>[src]

Returns the page size of the underlying operating system.

pub fn new(size: usize, wrap: usize) -> Result<Buffer, Error>[src]

Creates a new circular buffer with the given size and wrap. The returned size and wrap will be rounded up to an integer multiple of the page size. The wrap value cannot be larger than size, and both can be zero to get exactly the page size.

pub fn size(&self) -> usize[src]

Returns the size of the circular buffer.

pub fn wrap(&self) -> usize[src]

Returns the wrap of the circular buffer.

pub fn as_slice(&self) -> &[u8][src]

Returns an immutable slice of the circular buffer. The last wrap many bytes are mapped to the first wrap many bytes, so you can read the same content at both places.

pub fn as_mut_slice(&mut self) -> &mut [u8][src]

Returns a mutable slice of the circular buffer. The last wrap many bytes are mapped to the first wrap many bytes, so you can read and write the same content at both places.

Trait Implementations

impl Drop for Buffer[src]

impl<I: SliceIndex<[u8]>> Index<I> for Buffer[src]

type Output = I::Output

The returned type after indexing.

impl<I: SliceIndex<[u8]>> IndexMut<I> for Buffer[src]

impl Send for Buffer[src]

impl Sync for Buffer[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.