pub struct Spool { /* private fields */ }Expand description
Append-only durable spool file.
The byte cap and the running total are raw MaxSpoolBytes and
SpoolBytes newtypes. The spool adds and compares both of them exactly,
which an f64-backed [ByteSize] cannot promise. The quantity stays the
boundary type: Spool::open takes one and Spool::size returns one.
Implementations§
Source§impl Spool
impl Spool
Sourcepub fn resume_point(&self) -> Result<Option<(u64, [u8; 32])>, AuditError>
pub fn resume_point(&self) -> Result<Option<(u64, [u8; 32])>, AuditError>
The (next_seq, head) from the last chained record in the spool.
A chained record is a record that is not a checkpoint. Returns None if
the spool has no chained record.
§Errors
Returns an error if the spool file cannot be opened or read.
Source§impl Spool
impl Spool
Sourcepub fn open(dir: &Path, max_size: ByteSize) -> Result<Self, AuditError>
pub fn open(dir: &Path, max_size: ByteSize) -> Result<Self, AuditError>
Open the spool and recover its existing contents.
This function creates the directory and the file if they do not exist.
§Errors
Returns an error if the spool directory cannot be created. Returns an error if the spool file cannot be opened, read, or truncated.
Sourcepub fn open_with_sync_every(
dir: &Path,
max_size: ByteSize,
sync_every: NonZeroU64,
) -> Result<Self, AuditError>
pub fn open_with_sync_every( dir: &Path, max_size: ByteSize, sync_every: NonZeroU64, ) -> Result<Self, AuditError>
Open the spool with an explicit append-to-fsync cadence.
A cadence of N syncs after every N successful appends. Appends before
that boundary are visible after a process crash but are not promised to
survive power loss until Self::sync succeeds.
§Errors
Returns an error if the spool directory cannot be created. Returns an error if the spool file cannot be opened, read, synced, or truncated.
pub fn is_empty(&self) -> bool
pub fn count(&self) -> RecordCount
Sourcepub fn recovered_torn_tail(&self) -> bool
pub fn recovered_torn_tail(&self) -> bool
Whether Spool::open found a torn tail frame and cut it off.
A crash partway through an append leaves a frame whose length prefix
promises more bytes than follow it. open heals that, and this reports
whether it had to – healing a spool that was intact would mean
discarding good bytes, so the two cases are worth telling apart.
Sourcepub fn append(&mut self, record: &AuditRecord) -> Result<bool, AuditError>
pub fn append(&mut self, record: &AuditRecord) -> Result<bool, AuditError>
Append a record to the spool.
Returns Ok(false) if the record would make the spool exceed the
configured cap.
§Errors
Returns an error if the seek, write, rollback, or configured sync on the spool file fails.
Sourcepub fn sync(&mut self) -> Result<(), AuditError>
pub fn sync(&mut self) -> Result<(), AuditError>
Force all appended records to stable storage.
Callers using a sync cadence greater than one use this before reporting a durable acknowledgement.
§Errors
Returns an error if the spool file cannot be synced.
Sourcepub fn read_all(&self) -> Result<Vec<AuditRecord>, AuditError>
pub fn read_all(&self) -> Result<Vec<AuditRecord>, AuditError>
Read every record from the start of the spool, in order.
§Errors
Returns an error if the spool file cannot be opened or read.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Spool
impl RefUnwindSafe for Spool
impl Send for Spool
impl Sync for Spool
impl Unpin for Spool
impl UnsafeUnpin for Spool
impl UnwindSafe for Spool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<F> FnGhost for F
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);