InPlaceFile

Struct InPlaceFile 

Source
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

Source

pub fn reader(&self) -> &File

The reader file handle

Source

pub fn writer(&self) -> &File

The writer file handle

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for InPlaceFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.