Skip to main content

FileSink

Struct FileSink 

Source
pub struct FileSink<W: Write> { /* private fields */ }
Available on crate feature std only.
Expand description

Append-only file-backed Sink.

Wraps any W: io::Write and serialises records through the stable crate::codec. The format header is written exactly once, by FileSink::open_or_create when the target file is empty.

Writes are not auto-flushed. Call FileSink::flush (or wrap the inner writer in a BufWriter and rely on Drop) at appropriate checkpoints — a typical pattern is flushing after every append or after every batch.

Implementations§

Source§

impl FileSink<BufWriter<File>>

Source

pub fn open_or_create(path: impl AsRef<Path>) -> Result<Self>

Available on crate feature alloc only.

Open path for append-only audit writes, creating it if absent.

On a freshly-created file this writes the format header. On an existing file this validates the header and positions the writer at end-of-file. The underlying File is wrapped in a BufWriter.

§Errors

Surface I/O errors from opening, validating, or seeking the file. A bad existing header is reported as io::ErrorKind::InvalidData.

Source§

impl<W: Write> FileSink<W>

Source

pub fn new(writer: W) -> Self

Available on crate feature alloc only.

Wrap an existing writer that is already positioned correctly (header already written, ready to append records).

Most callers want FileSink::open_or_create instead.

Source

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

Available on crate feature alloc only.

Flush the underlying writer.

§Errors

Surfaces the writer’s I/O error verbatim.

Source

pub fn into_writer(self) -> W

Available on crate feature alloc only.

Consume the sink and return the underlying writer.

Trait Implementations§

Source§

impl<W: Write> Sink for FileSink<W>

Available on crate feature alloc only.
Source§

fn write(&mut self, record: &Record<'_>) -> Result<(), SinkError>

Persist a single record. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<W> UnsafeUnpin for FileSink<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for FileSink<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> 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.