Skip to main content

LogWriter

Struct LogWriter 

Source
pub struct LogWriter {
    pub(crate) raw: NonNull<TlwWriter>,
}
Expand description

One SQLite log being written by the C++ writer.

Create it, write the header, then the pages between begin_log and end_log. Dropping it closes the database; pages written since begin_log without an end_log are rolled back.

Fields§

§raw: NonNull<TlwWriter>

The C handle; never null, and owned: closed exactly once, in Drop.

Implementations§

Source§

impl LogWriter

Source

pub fn create( path: &Path, config: &Config, replace: bool, ) -> Result<Self, WriterError>

Creates a log at path for a tag with config, replacing an existing file when replace is true.

§Errors

When the library was built from a different interface version, the path is not UTF-8 or contains a NUL, or the database cannot be created (the writer’s message says why).

Source

pub fn write_header(&mut self, header: &LogHeader) -> Result<(), WriterError>

Writes header: its parts, then the info, calibration and state tables and the tag’s data tables. Call once, first.

The parts are passed one at a time (tlw_header_add) and written together (tlw_write_header), so the C side never needs a header message of its own and proto/ gains nothing for this interface. The parts accumulate in the handle: a second call would pass them again and the writer would fail creating tables that exist.

§Errors

When a part is rejected or the writer fails, for example because the header’s tag type differs from the one given to create.

Source

pub fn write_info( &mut self, field: &str, value: &str, ) -> Result<(), WriterError>

Adds a row to the info table, after the header.

§Errors

When a string contains a NUL byte, or the writer fails.

Source

pub fn begin_log(&mut self) -> Result<(), WriterError>

Starts the data log: the pages that follow are written in one transaction, committed by end_log.

§Errors

When the transaction cannot be started.

Source

pub fn write_log(&mut self, ack: &Ack) -> Result<usize, WriterError>

Decodes and writes one data-log page, the Ack as the tag returned it.

Returns how many log records the page consumed, which advances the index of the next page to request, or 0 at the end of the log. Both depend on the tag type, which is why the writer decides them, and why a download must call this synchronously, page by page: the next request cannot be formed until it returns.

§Errors

When the writer rejects the page or the database write fails.

Source

pub fn end_log(&mut self) -> Result<(), WriterError>

Commits the data log.

§Errors

When the commit fails.

Source

pub(crate) fn add_part( &mut self, kind: c_int, message: &impl Message, ) -> Result<(), WriterError>

Passes one header part to the writer.

§Errors

When the library cannot parse the encoding (a version mismatch).

Source

pub(crate) fn check(&self, status: c_int) -> Result<(), WriterError>

Turns a C status (1 success, 0 failure) into a Result.

§Errors

When status is not 1, with the handle’s last error.

Source

pub(crate) fn last_error(&self) -> WriterError

The handle’s last error, copied out of the library.

Trait Implementations§

Source§

impl Drop for LogWriter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for LogWriter

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.