[][src]Struct vmcircbuf::Buffer

pub struct Buffer { /* fields omitted */ }

A raw circular buffer of bytes. The buffer holds exactly size many bytes, and any at most wrap many bytes can be accessed as a continuos slice where the end wraps over to the beginning. This trick is performed with virtual memory, the same physical pages are mapped both at the start of an buffer and after 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 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 slice(&self, start: usize, count: usize) -> &[u8][src]

Returns an immutable slice of the circular buffer starting at start and containing count many elements. Note, that start + count cannot be larger than size + wrap. If start + count is bigger than size, then the returned slice will magically wrap over to the beginning of the buffer.

pub fn slice_mut(&mut self, start: usize, count: usize) -> &mut [u8][src]

This is the mutable analog of the slice method.

pub unsafe fn slice_unchecked(&self, start: usize, count: usize) -> &[u8][src]

This is the unsafe version of the slice method.

Safety

Make sure that start + count <= size + wrap before calling this method.

pub unsafe fn slice_mut_unchecked(
    &mut self,
    start: usize,
    count: usize
) -> &mut [u8]
[src]

This is the unsafe version of the slice_mut method.

Safety

Make sure that start + count <= size + wrap before calling this method.

Trait Implementations

impl Drop 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.