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.
Note that permissions will be set to 0o666
, which usually results in 0o644
after passing a default umask, on Unix systems.
§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.
Sourcepub fn acquire_to_update_resource_with_permissions(
at_path: impl AsRef<Path>,
mode: Fail,
boundary_directory: Option<PathBuf>,
make_permissions: impl Fn() -> Permissions,
) -> Result<File, Error>
pub fn acquire_to_update_resource_with_permissions( at_path: impl AsRef<Path>, mode: Fail, boundary_directory: Option<PathBuf>, make_permissions: impl Fn() -> Permissions, ) -> Result<File, Error>
Like acquire_to_update_resource()
, but allows to set filesystem permissions using make_permissions
.
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>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> 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§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)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
)