Skip to main content

AtomicFile

Struct AtomicFile 

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

Based on BasicAtomicFile which makes sure that updates are all-or-nothing. Performs commit asyncronously.

#Example

use atom_file::{AtomicFile,DummyFile,MemFile,Storage};
let mut af = AtomicFile::new(MemFile::new(), DummyFile::new());
af.write( 0, &[1,2,3,4] );
af.commit(4);
af.wait_complete();

Atomic file has two maps of writes. On commit, the latest batch of writes are sent to be written to underlying storage, and are also applied to the second map in the “CommitFile”. The CommitFile map is reset when all the updates to underlying storage have been applied.

Implementations§

Source§

impl AtomicFile

Source

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

Construct AtomicFile with default limits. stg is the main underlying storage, upd is temporary storage for updates during commit.

Source

pub fn new_with_limits( stg: Box<dyn Storage>, upd: Box<dyn Storage>, lim: &Limits, ) -> Box<Self>

Construct Atomic file with specified limits.

Trait Implementations§

Source§

impl Storage for AtomicFile

Source§

fn commit(&mut self, size: u64)

Finish write transaction, size is new size of underlying storage.
Source§

fn size(&self) -> u64

Get the size of the underlying storage. Note : this is valid initially and after a commit but is not defined after write is called.
Source§

fn read(&self, start: u64, data: &mut [u8])

Read data.
Source§

fn write_data(&mut self, start: u64, data: Data, off: usize, len: usize)

Write Data slice.
Source§

fn write(&mut self, start: u64, data: &[u8])

Write byte slice to storage.
Source§

fn wait_complete(&self)

Wait until current writes are complete.
Source§

fn write_vec(&mut self, start: u64, data: Vec<u8>)

Write byte Vec.
Source§

fn write_u64(&mut self, start: u64, value: u64)

Write u64.
Source§

fn read_u64(&self, start: u64) -> u64

Read u64.
Source§

fn clone(&self) -> Box<dyn Storage>

Clone. note: provided method panics.

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

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.