Skip to content

Commit

Permalink
Manual close handle for File to allow handling of potential errors
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkrull committed Mar 27, 2024

Unverified

This user has not yet uploaded their public signing key.
1 parent f38624e commit 283e5f6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/filesystem/files.rs
Original file line number Diff line number Diff line change
@@ -128,6 +128,15 @@ where
pub fn flush(&mut self) -> Result<(), Error<D::Error>> {
self.volume_mgr.flush_file(self.raw_file)
}

/// Consume the `File` handle and close it. The behavior of this is similar
/// to using [`core::mem::drop`] or letting the `File` go out of scope,
/// except if the file fails to close properly, this returns an error,
/// whereas the automatic drop will panic. This method is therefore hihgly
/// recommended for closing files over just dropping them.
pub fn close(self) -> Result<(), Error<D::Error>> {
self.volume_mgr.close_file(self.raw_file)
}
}

impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Drop

0 comments on commit 283e5f6

Please sign in to comment.