Writer

Struct Writer 

Source
pub struct Writer<W: Write> { /* private fields */ }

Implementations§

Source§

impl<W: Write> Writer<W>

Source

pub fn append<T: Encode>(&mut self, record: T) -> Result<(), T>

Append the record (aka transaction) T to the segment.

If the number of currently buffered records would exceed max_records_in_commit after the method returns, the argument is returned in an Err and not appended to this writer’s buffer.

Otherwise, the record is encoded and and stored in the buffer.

An Err result indicates that Self::commit should be called in order to flush the buffered records to persistent storage.

Source

pub fn commit(&mut self) -> Result<Option<Committed>>

Write the current Commit to the underlying io::Write.

Will do nothing if the current commit is empty (i.e. Commit::n is zero). In this case, None is returned.

Otherwise Some Committed is returned, providing some metadata about the commit.

Source

pub fn epoch(&self) -> u64

Get the current epoch.

Source

pub fn set_epoch(&mut self, epoch: u64)

Update the epoch.

The caller must ensure that:

  • The new epoch is greater than the current epoch.
  • Self::commit has been called as appropriate.
Source

pub fn min_tx_offset(&self) -> u64

The smallest transaction offset in this segment.

Source

pub fn next_tx_offset(&self) -> u64

The next transaction offset to be written if Self::commit was called.

Source

pub fn is_empty(&self) -> bool

true if the segment contains no commits.

The segment will, however, contain a header. This thus violates the convention that is_empty == (len == 0).

Source

pub fn len(&self) -> u64

Number of bytes written to this segment, including the header.

Trait Implementations§

Source§

impl<W: Debug + Write> Debug for Writer<W>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<W: Write + FileLike> FileLike for Writer<W>

Source§

fn fsync(&mut self) -> Result<()>

Source§

fn ftruncate(&mut self, tx_offset: u64, size: u64) -> Result<()>

Auto Trait Implementations§

§

impl<W> Freeze for Writer<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Writer<W>
where W: RefUnwindSafe,

§

impl<W> Send for Writer<W>
where W: Send,

§

impl<W> Sync for Writer<W>
where W: Sync,

§

impl<W> Unpin for Writer<W>
where W: Unpin,

§

impl<W> UnwindSafe for Writer<W>
where W: 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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