Skip to main content

AtomicFile

Struct AtomicFile 

Source
pub struct AtomicFile { /* private fields */ }
Expand description

One named file capability. It reads, creates, replaces and removes bytes without exposing a path. Replacement atomically installs a complete version.

Implementations§

Source§

impl AtomicFile

Source

pub fn read_optional(&self) -> Result<Option<Vec<u8>>, FileError>

Read the complete file. Only a missing file is None; other errors retain their operating-system cause.

Source

pub fn open_reader(&self) -> Result<FileReader, ObservationError>

Open this owned file for checked scans and positioned reads.

Source

pub fn replace(&self, bytes: &[u8]) -> Result<(), FileError>

Write and sync a temporary sibling, replace the target, then sync its directory. The parent must already exist. Concurrent writers each install one complete version; a failed pre-rename write leaves it alone.

Windows uses POSIX replacement on a write-through file handle, which flushes the rename’s metadata on NTFS. This requires FileRenameInfoEx and a filesystem supporting POSIX replacement. Windows 10 before 1607 lacks that API; unsupported systems return the OS error without falling back to a rename that can fail while readers hold old versions open.

Source

pub fn write_recorded(&self, bytes: &[u8]) -> Result<(), FileError>

Write and sync complete bytes at this name, then flush its directory and the drive’s cache, as a batch of this one file, with no temporary sibling. The caller records the name as its own first, so bytes a crash interrupts stay recorded for removal. Anything but a regular file there is refused before a byte is written.

Source

pub fn overwrite_at( &self, offset: u64, bytes: &[u8], ) -> Result<(), ObservationError>

Write bytes over this existing file’s bytes from offset, which they must lie within, and hand them to the drive. Readers can see some of the old bytes and some of the new while it writes, and a crash can leave them so: only bytes that check themselves, as a cache’s authenticated chunks do, are written this way.

Source

pub fn set_len(&self, length: u64) -> Result<(), ObservationError>

Give this existing file length bytes, cutting it short or adding zeros at its end, and hand the change to the drive.

Source

pub fn remove(&self) -> Result<(), FileError>

Remove the owned file; an absent file is success. On Unix, sync the directory even on a retry after an earlier directory-sync failure. A missing parent is already absent and needs no durability barrier.

Source

pub fn remove_with_temporaries(&self) -> Result<(), FileError>

Remove the owned file and every temporary sibling a write of it left, as a crash or a failed removal does: each holds a whole version of its bytes. The caller holds what guards this file’s writes, so none of them is a write in flight.

Source

pub fn leave_temporary(&self, bytes: &[u8]) -> PathBuf

Leave a temporary sibling holding bytes, as a crash between writing it and renaming it does, and say where.

Trait Implementations§

Source§

impl Clone for AtomicFile

Source§

fn clone(&self) -> AtomicFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AtomicFile

Source§

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

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
§

impl<T> ErasedDestructor for T
where T: 'static,