pub struct AtomicFileOutput { /* private fields */ }Expand description
将完整结果先写入同目录临时文件,再原子替换目标文件。
§Examples
use easypdf_core::AtomicFileOutput;
AtomicFileOutput::new("/tmp/output.pdf")
.write(b"%PDF-1.4 ...");Implementations§
Source§impl AtomicFileOutput
impl AtomicFileOutput
Sourcepub fn write_with_fsync(&self, data: &[u8]) -> Result<()>
pub fn write_with_fsync(&self, data: &[u8]) -> Result<()>
使用显式 fsync 写入数据,然后原子替换目标。
在 macOS 上映射到 fcntl(F_FULLFSYNC)(通过 Rust 的
std::fs::File::sync_all),在 Linux 上映射到 fdatasync,
在 Windows 上映射到 FlushFileBuffers。全部通过安全 Rust。
§Errors
任何阶段的 I/O 失败时返回错误。
Sourcepub fn write_with_backup(&self, data: &[u8]) -> Result<()>
pub fn write_with_backup(&self, data: &[u8]) -> Result<()>
备份现有文件(如果有),然后原子写入新数据。
写入成功则移除备份。写入失败则将备份恢复到原始路径。
备份创建在同目录的 <target>.bak。
§Errors
备份创建、写入或恢复失败时返回错误。
Sourcepub fn atomic_replace<F>(&self, writer: F) -> Result<()>
pub fn atomic_replace<F>(&self, writer: F) -> Result<()>
Trait Implementations§
Source§impl Clone for AtomicFileOutput
impl Clone for AtomicFileOutput
Source§fn clone(&self) -> AtomicFileOutput
fn clone(&self) -> AtomicFileOutput
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AtomicFileOutput
impl RefUnwindSafe for AtomicFileOutput
impl Send for AtomicFileOutput
impl Sync for AtomicFileOutput
impl Unpin for AtomicFileOutput
impl UnsafeUnpin for AtomicFileOutput
impl UnwindSafe for AtomicFileOutput
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
Converts
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> ⓘ
Converts
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