Struct reth_nippy_jar::NippyJarWriter

source ·
pub struct NippyJarWriter<H: NippyJarHeader = ()> { /* private fields */ }
Expand description

Writer of NippyJar. Handles table data and offsets only.

Table data is written directly to disk, while offsets and configuration need to be flushed by calling commit().

§Offset file layout

The first byte is the size of a single offset in bytes, m. Then, the file contains n entries, each with a size of m. Each entry represents an offset, except for the last entry, which represents both the total size of the data file, as well as the next offset to write new data to.

§Data file layout

The data file is represented just as a sequence of bytes of data without any delimiters

Implementations§

source§

impl<H: NippyJarHeader> NippyJarWriter<H>

source

pub fn new(jar: NippyJar<H>) -> Result<Self, NippyJarError>

Creates a NippyJarWriter from NippyJar.

If will always attempt to heal any inconsistent state when called.

source

pub const fn user_header(&self) -> &H

Returns a reference to H of NippyJar

source

pub fn user_header_mut(&mut self) -> &mut H

Returns a mutable reference to H of NippyJar.

Since there’s no way of knowing if H has been actually changed, this sets self.dirty to true.

source

pub const fn is_dirty(&self) -> bool

Returns whether there are changes that need to be committed.

source

pub const fn rows(&self) -> usize

Gets total writer rows in jar.

source

pub fn into_jar(self) -> NippyJar<H>

Consumes the writer and returns the associated NippyJar.

source

pub fn append_rows( &mut self, column_values_per_row: Vec<impl IntoIterator<Item = ColumnResult<impl AsRef<[u8]>>>>, num_rows: u64, ) -> Result<(), NippyJarError>

Appends rows to data file. fn commit() should be called to flush offsets and config to disk.

column_values_per_row: A vector where each element is a column’s values in sequence, corresponding to each row. The vector’s length equals the number of columns.

source

pub fn append_column( &mut self, column: Option<ColumnResult<impl AsRef<[u8]>>>, ) -> Result<(), NippyJarError>

Appends a column to data file. fn commit() should be called to flush offsets and config to disk.

source

pub fn prune_rows(&mut self, num_rows: usize) -> Result<(), NippyJarError>

Prunes rows from data and offsets file and updates its configuration on disk

source

pub fn commit(&mut self) -> Result<(), NippyJarError>

Commits configuration and offsets to disk. It drains the internal offset list.

source

pub fn commit_without_sync_all(&mut self) -> Result<(), NippyJarError>

Available on crate feature test-utils only.
source

pub fn data_file(&mut self) -> &mut BufWriter<File>

Available on crate feature test-utils only.
source

pub const fn jar(&self) -> &NippyJar<H>

Available on crate feature test-utils only.

Trait Implementations§

source§

impl<H: Debug + NippyJarHeader> Debug for NippyJarWriter<H>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<H> Freeze for NippyJarWriter<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for NippyJarWriter<H>
where H: RefUnwindSafe,

§

impl<H> Send for NippyJarWriter<H>

§

impl<H> Sync for NippyJarWriter<H>

§

impl<H> Unpin for NippyJarWriter<H>
where H: Unpin,

§

impl<H> UnwindSafe for NippyJarWriter<H>
where H: 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.