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
sourceimpl 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.
sourceimpl 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
sourceimpl Read for File
impl Read for File
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · sourcefn 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 moresourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · sourcefn 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 · sourcefn 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 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)sourcefn 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 · sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresourceimpl Seek for File
impl Seek for File
sourcefn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · sourcefn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
sourceimpl Write for File
impl Write for File
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)