Open
Conversation
friendlier syntax for users: instead of creating a new FileLock(), call e.g. file.lock_exclusive_guarded()
FileLockGuard takes ownership of the file, so you can still access it mutably after locking. FileLockError needs improvement, should implement Error Instead of making fs2::FileExt depend on Sized, we should make guard::FileExt a separate trait
simplifies error handling, since we don't need to pass ownership back through error. we directly return io::Error
not needed, since we no longer own the file
move code from "guard" module to root
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm new to Rust. I appreciate any comments on this.
These scoped file locks are inspired by Mutex and MutexGuard. Example usage is in FileExt doc comments.
FileLockGuard borrows the file mutably, so it can implement DerefMut. You may need to borrow immutably; I don't have an elegant solution for that. My typical use case is with mutable files.
FileLockGuard::drop()panics if unlock fails, but unlock shouldn't fail through normal usage.Thank you!