pub struct File { /* private fields */ }
Expand description
Locks a resource to eventually be overwritten with the content of this file.
Dropping the file without committing will delete it, leaving the underlying resource unchanged.
Implementations§
source§impl File
impl File
sourcepub fn acquire_to_update_resource(
at_path: impl AsRef<Path>,
mode: Fail,
boundary_directory: Option<PathBuf>
) -> Result<File, Error>
pub fn acquire_to_update_resource( at_path: impl AsRef<Path>, mode: Fail, boundary_directory: Option<PathBuf> ) -> Result<File, Error>
Create a writable lock file with failure mode
whose content will eventually overwrite the given resource at_path
.
If boundary_directory
is given, non-existing directories will be created automatically and removed in the case of
a rollback. Otherwise the containing directory is expected to exist, even though the resource doesn’t have to.
Warning of potential resource leak
Please note that the underlying file will remain if destructors don’t run, as is the case when interrupting the application. This results in the resource being locked permanently unless the lock file is removed by other means. See the crate documentation for more information.
source§impl File
impl File
sourcepub fn with_mut<T>(
&mut self,
f: impl FnOnce(&mut File) -> Result<T>
) -> Result<T>
pub fn with_mut<T>( &mut self, f: impl FnOnce(&mut File) -> Result<T> ) -> Result<T>
Obtain a mutable reference to the write handle and call f(out)
with it.
sourcepub fn close(self) -> Result<Marker>
pub fn close(self) -> Result<Marker>
Close the lock file to prevent further writes and to save system resources.
A call to Marker::commit()
is allowed on the Marker
to write changes back to the resource.
sourcepub fn resource_path(&self) -> PathBuf
pub fn resource_path(&self) -> PathBuf
Return the path at which the locked resource resides
Trait Implementations§
source§impl Read for File
impl Read for File
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read
. Read moresource§impl Seek for File
impl Seek for File
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
source§impl Write for File
impl Write for File
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
)