Struct rustdb::block::BlockStg

source ·
pub struct BlockStg { /* private fields */ }
Expand description

Manages allocation and deallocation of numbered relocatable fixed size blocks from underlying Storage.

Blocks are numbered. A map of the physical location of each block is kept at the start of the storage (after the header).

Physical blocks can be relocated by adjusting the map entry to point to the new location.

On save, the map of free block numbers is processed and any associated physical blocks are freed.

When a physical block is freed, the last physical block is relocated to fill it.

Implementations§

source§

impl BlockStg

source

pub fn new(stg: Box<dyn Storage>, blk_cap: u64) -> Self

Construct BlockStg with specified underlying Storage and block capacity. For existing file, block capacity will be read from file header.

source

pub fn blk_cap(&self) -> u64

Get the block capacity.

source

pub fn nsz(&self) -> usize

Get size of block number in bytes.

source

pub fn is_new(&self) -> bool

Is this new storage.

source

pub fn new_block(&mut self) -> u64

Allocate a new block number.

source

pub fn drop_block(&mut self, bn: u64)

Release a block number ( no longer valid ).

source

pub fn write(&mut self, bn: u64, offset: u64, data: &[u8])

Write data to specified numbered block at specified offset.

source

pub fn write_data( &mut self, bn: u64, offset: u64, data: Data, s: usize, n: usize )

Write slice of Data to specified numbered block at specified offset.

source

pub fn read(&self, bn: u64, offset: u64, data: &mut [u8])

Read data from specified numbered block and offset.

source

pub fn set_rsvd(&mut self, rsvd: [u8; 16])

Set the reserved area in the storage header.

source

pub fn get_rsvd(&self) -> [u8; 16]

Get the reserved area from the storage header.

source

pub fn save(&mut self)

Save changes to underlying storage.

source

pub fn wait_complete(&self)

Wait for save to complete.

Auto Trait Implementations§

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>,

§

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>,

§

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.