Struct Pager

Source
pub struct Pager { /* private fields */ }
Expand description

Memory pager instance. Manages Page instances.

Implementations§

Source§

impl Pager

Source

pub fn new(page_size: usize) -> Self

Create a new Pager instance with a page_size.

Source

pub fn from_file( file: &mut File, page_size: usize, offset: Option<usize>, ) -> Result<Self, Error>

Create a new instance from a file.

This is particularly useful when restoring the memory-pager from disk, as it’s possible to open a file, and directly convert it into a pager instance.

§Options

The third argument is an optional offset of usize. This is useful to ignore the first few bytes if the file has a header that isn’t part of the bitfield’s body.

§Errors

This method will return an error if the File length is not a multiple of page_size. It can also fail if it’s unable to read the file’s metadata.

§Examples
use failure::Error;
use pager::Pager;
use std::fs;

fn main () -> Result<(), Error> {
  let mut file = fs::File::open("tests/fixtures/40_empty.bin")?;
  let page_size = 10;
  let _pager = Pager::from_file(&mut file, page_size, None)?;
  Ok(())
}
Source

pub fn get_mut_or_alloc(&mut self, page_num: usize) -> &mut Page

Get a Page mutably. The page will be allocated on first access.

Source

pub fn get(&self, page_num: usize) -> Option<&Page>

Get a Page wrapped in an Option enum. Does not allocate on access.

Source

pub fn get_mut(&mut self, page_num: usize) -> Option<&mut Page>

Get a mutable Page wrapped in an Option enum. Does not allocate on access.

Source

pub fn len(&self) -> usize

The number of pages held by memory-pager. Doesn’t account for empty entries. Comparable to vec.len() in usage.

Source

pub fn is_empty(&self) -> bool

check whether the length is zero.

Source

pub fn page_size(&self) -> usize

Get the memory page size in bytes.

Source

pub fn iter(&self) -> Iter<'_>

Iterate over &Pages.

Trait Implementations§

Source§

impl Debug for Pager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Pager

Create a new Pager instance with a page_size of 1024.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Pager

§

impl RefUnwindSafe for Pager

§

impl Send for Pager

§

impl Sync for Pager

§

impl Unpin for Pager

§

impl UnwindSafe for Pager

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.