Skip to content

add scoped FileLockGuard#22

Open
coryshrmn wants to merge 8 commits intodanburkert:masterfrom
coryshrmn:master
Open

add scoped FileLockGuard#22
coryshrmn wants to merge 8 commits intodanburkert:masterfrom
coryshrmn:master

Conversation

@coryshrmn
Copy link
Copy Markdown

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!

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant