Skip to main content

Atomic

Struct Atomic 

Source
pub struct Atomic<R: ResourceExt> { /* private fields */ }
Expand description

Decorator for crash-safe whole-file writes.

For file-backed resources: write-rename pattern ensures that the target file is either the old version or the new version — never a partial write.

For in-memory resources: direct delegation (crash-safety is not applicable).

Implementations§

Source§

impl<R: ResourceExt> Atomic<R>

Source

pub fn new(inner: R) -> Self

Wrap a resource for crash-safe writes.

Source§

impl<R: ResourceExt> Atomic<R>

Source

pub fn write_all_durable(&self, data: &[u8]) -> StorageResult<()>

Write the whole payload atomically AND durably: like ResourceExt::write_all but also sync_datas the temp file before the atomic rename. Returns only after the bytes are physically on disk.

Use this on explicit checkpoint paths where the caller wants post-return durability. Per-mutation flushes should keep using the cheaper ResourceExt::write_all (best-effort, atomic rename only).

For memory-backed inners (no filesystem path) durability is meaningless; the call falls back to the same passthrough as write_all.

§Errors

Propagates filesystem errors from temp creation, write, sync_data, rename, or the inner’s post-rename commit.

Trait Implementations§

Source§

impl<R: Clone + ResourceExt> Clone for Atomic<R>

Source§

fn clone(&self) -> Atomic<R>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<R: Debug + ResourceExt> Debug for Atomic<R>

Source§

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

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

impl<R: ResourceExt> ResourceExt for Atomic<R>

Source§

fn write_all(&self, data: &[u8]) -> StorageResult<()>

Write entire contents and commit atomically. Read more
Source§

fn commit(&self, final_len: Option<u64>) -> StorageResult<()>

Mark the resource as fully written. Read more
Source§

fn fail(&self, reason: String)

Mark the resource as failed.
Source§

fn len(&self) -> Option<u64>

Get the committed length, if known.
Source§

fn path(&self) -> Option<&Path>

Get the file path, if backed by a file. Read more
Source§

fn reactivate(&self) -> StorageResult<()>

Reactivate a committed resource for continued writing. Read more
Source§

fn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>

Read data at the given offset into buf. Read more
Source§

fn status(&self) -> ResourceStatus

Get resource status.
Source§

fn wait_range(&self, range: Range<u64>) -> StorageResult<WaitOutcome>

Wait until the given byte range is available. Read more
Source§

fn write_at(&self, offset: u64, data: &[u8]) -> StorageResult<()>

Write data at the given offset. Read more
Source§

fn contains_range(&self, _range: Range<u64>) -> bool

Check if the given byte range is fully covered by available data (non-blocking). Read more
Source§

fn is_empty(&self) -> bool

Returns true if the resource has been committed with zero length.
Source§

fn next_gap(&self, _from: u64, _limit: u64) -> Option<Range<u64>>

Find the first gap in available data starting from from, up to limit. Read more
Source§

fn read_into(&self, buf: &mut Vec<u8>) -> StorageResult<usize>

Read the entire resource contents into a caller-provided buffer. Read more

Auto Trait Implementations§

§

impl<R> Freeze for Atomic<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Atomic<R>
where R: RefUnwindSafe,

§

impl<R> Send for Atomic<R>

§

impl<R> Sync for Atomic<R>

§

impl<R> Unpin for Atomic<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for Atomic<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for Atomic<R>
where R: 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> 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.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,