Struct Layer

Source
pub struct Layer<'l, Stream: Write + Read + Seek> {
    pub bounds: Option<Range<u64>>,
    pub size: u64,
    pub read_cursor: (u64, usize),
    /* private fields */
}
Expand description

Represents a layer (either in the heap or disk) in the stack-db that stacks

Fields§

§bounds: Option<Range<u64>>

The bounds of the layer; the range of the layer

§size: u64

The total size of all the writes in the layer

§read_cursor: (u64, usize)

The current read cursor to speed up sequential reads

Implementations§

Source§

impl<'l, Stream: Write + Read + Seek> Layer<'l, Stream>

Source

pub fn new(stream: Stream) -> Self

Source

pub fn load(stream: Stream) -> Result<Self, Error>

Source

pub fn check_collisions( &mut self, range: &Range<u64>, ) -> Result<Box<[Range<u64>]>, Error>

Checks for collisions on the current layer

Source

pub fn check_non_collisions( &self, range: &Range<u64>, collisions: &[Range<u64>], ) -> Box<[Range<u64>]>

Takes in the ordered output of the check_collisions function to find the inverse

Source

pub fn read_unchecked( &mut self, addr: &Range<u64>, ) -> Result<(Range<usize>, Cow<'_, [u8]>), Error>

Reads from the layer unchecked and returns the section data and the desired relative range within the section.

warning: will throw out-of-bounds error (or undefined behaviour) if the read is accross two sections (each read can only be on one section of a layer)

Source

pub fn write_unchecked( &mut self, idx: u64, data: Cow<'l, [u8]>, ) -> Result<(), Error>

Writes to the heap layer without checking for collisions

WARNING: the layer will be corrupt (due to undefined behaviour) if there are any collisions; this function is meant to be used internally

Source

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

Moves the layer from the heap to disk

Trait Implementations§

Source§

impl<'l, Stream: Debug + Write + Read + Seek> Debug for Layer<'l, Stream>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'l, Stream> Freeze for Layer<'l, Stream>
where Stream: Freeze,

§

impl<'l, Stream> RefUnwindSafe for Layer<'l, Stream>
where Stream: RefUnwindSafe,

§

impl<'l, Stream> Send for Layer<'l, Stream>
where Stream: Send,

§

impl<'l, Stream> Sync for Layer<'l, Stream>
where Stream: Sync,

§

impl<'l, Stream> Unpin for Layer<'l, Stream>
where Stream: Unpin,

§

impl<'l, Stream> UnwindSafe for Layer<'l, Stream>
where Stream: 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, 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.