Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add scoped FileLockGuard #22

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

coryshrmn
Copy link

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