pub struct AtomicOutputFile { /* private fields */ }Expand description
Crash-safe output writing: content goes to a hidden temporary file next
to final_path, and AtomicOutputFile::commit fsyncs it and renames
it into place. Until then the final path holds whatever the caller put
there (typically an empty placeholder claiming the name), so a crash or
error never leaves a truncated file that looks complete. Dropping
without committing removes the temporary file.
A hard crash (kill, power loss) can still leave the empty placeholder
and a .<name>.tmpN file behind; both are inert and safe to delete
manually. We deliberately never auto-clean them: deleting files we
cannot prove we created is worse than the litter.
Implementations§
Source§impl AtomicOutputFile
impl AtomicOutputFile
Sourcepub fn start(final_path: PathBuf) -> WorkflowResult<Self>
pub fn start(final_path: PathBuf) -> WorkflowResult<Self>
Starts writing for final_path, which the caller must already have
claimed (created) so the name is reserved under its own overwrite
policy.
Sourcepub fn as_file(&self) -> &File ⓘ
pub fn as_file(&self) -> &File ⓘ
The temporary file being written, e.g. to apply metadata before committing (rename preserves it).
Sourcepub fn commit(&mut self) -> WorkflowResult<()>
pub fn commit(&mut self) -> WorkflowResult<()>
Flushes the content to disk and atomically renames it over the final path (replacing the caller’s placeholder).
Trait Implementations§
Source§impl Drop for AtomicOutputFile
impl Drop for AtomicOutputFile
Source§impl Write for AtomicOutputFile
impl Write for AtomicOutputFile
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Auto Trait Implementations§
impl Freeze for AtomicOutputFile
impl RefUnwindSafe for AtomicOutputFile
impl Send for AtomicOutputFile
impl Sync for AtomicOutputFile
impl Unpin for AtomicOutputFile
impl UnsafeUnpin for AtomicOutputFile
impl UnwindSafe for AtomicOutputFile
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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