pub struct InPlaceFile { /* private fields */ }Expand description
A file that is currently being edited in-place.
An InPlaceFile instance can be obtained via InPlace::open().
An InPlaceFile provides two file handles, one for reading the contents of
the edited file and for writing its new contents. In order to update the
edited file with the written bytes, InPlaceFile::save() must be called
once writing is complete. Alternatively, calling
InPlaceFile::discard() will discard all written bytes and leave the
edited file unmodified.
Dropping an InPlaceFile without calling save() has the same effect as
calling discard(), except that any errors are ignored.
Implementations§
Source§impl InPlaceFile
impl InPlaceFile
Sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
The path to the edited file. If follow_symlinks was set to true,
this will be a canonical path; otherwise, the path is only guaranteed
to be absolute.
Sourcepub fn backup_path(&self) -> Option<&Path>
pub fn backup_path(&self) -> Option<&Path>
The path, if any, where the edited file will be backed up once
InPlaceFile::save() is called. This is an absolute path.
Sourcepub fn save(self) -> Result<(), InPlaceError>
pub fn save(self) -> Result<(), InPlaceError>
Save the unmodified edited file at the backup path, if any, and replace the edited file with the temporary output file.
The exact set & order of operations may change in a future version, but currently it is as follows:
-
The file handle for the edited file is closed.
-
If a backup path is set, move the edited file to that location.
-
Persist the temporary file at the edited file’s original location. If this fails, and a backup path is set, try to move the backup back to the original location, ignoring any errors.
§Errors
See the documentation for the variants of InPlaceErrorKind for the
operations that this method can fail on.
Sourcepub fn discard(self) -> Result<(), InPlaceError>
pub fn discard(self) -> Result<(), InPlaceError>
Close all filehandles and do not update or back up the edited file.
§Errors
See the documentation for the variants of InPlaceErrorKind for the
operations that this method can fail on.