Struct DataFile

Source
pub struct DataFile<T> { /* private fields */ }
Expand description

Data file (MMR) wrapper around an append-only file.

Implementations§

Source§

impl<T> DataFile<T>
where T: Readable + Writeable + Debug,

Source

pub fn open<P>( path: P, size_info: SizeInfo, version: ProtocolVersion, ) -> Result<DataFile<T>>
where P: AsRef<Path> + Debug,

Open (or create) a file at the provided path on disk.

Source

pub fn append(&mut self, data: &T) -> Result<u64>

Append an element to the file. Will not be written to disk until flush() is subsequently called. Alternatively discard() may be called to discard any pending changes.

Source

pub fn extend_from_slice(&mut self, data: &[T]) -> Result<u64>

Append a slice of multiple elements to the file. Will not be written to disk until flush() is subsequently called. Alternatively discard() may be called to discard any pending changes.

Source

pub fn read(&self, position: u64) -> Option<T>

Read an element from the file by position. Assumes we have already “shifted” the position to account for pruned data. Note: PMMR API is 1-indexed, but backend storage is 0-indexed.

Makes no assumptions about the size of the elements in bytes. Elements can be of variable size (handled internally in the append-only file impl).

Source

pub fn rewind(&mut self, position: u64)

Rewind the backend file to the specified position.

Source

pub fn flush(&mut self) -> Result<()>

Flush unsynced changes to the file to disk.

Source

pub fn discard(&mut self)

Discard any unsynced changes to the file.

Source

pub fn size(&self) -> u64

Size of the file in number of elements (not bytes).

Source

pub fn path(&self) -> &Path

Path of the underlying file

Source

pub fn release(&mut self)

Drop underlying file handles

Source

pub fn write_tmp_pruned(&self, prune_pos: &[u64]) -> Result<()>

Write the file out to disk, pruning removed elements.

Source

pub fn replace_with_tmp(&mut self) -> Result<()>

Replace with file at tmp path. Rebuild and initialize from new file.

Auto Trait Implementations§

§

impl<T> Freeze for DataFile<T>

§

impl<T> RefUnwindSafe for DataFile<T>
where T: RefUnwindSafe,

§

impl<T> Send for DataFile<T>
where T: Send,

§

impl<T> Sync for DataFile<T>
where T: Sync,

§

impl<T> Unpin for DataFile<T>
where T: Unpin,

§

impl<T> UnwindSafe for DataFile<T>
where T: UnwindSafe,

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> SafeBorrow<T> for T
where T: ?Sized,

Source§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V