Write an fslock wrapper with a Guard.
Right now the fslock crate has an LockFile
object that can exist in a locked and an unlocked state. That makes it not-so-suitable for use cases where we want to ensure that the lock is held whenever a given piece of code is entered and/or for as long as a given object exists. To solve that, I'm thinking of making a LockFileGuard
type that behaves more or less like MutexGuard
.
Bikeshed time: should there be data inside this type?
// OPTION 1:
impl FsMutex {
pub fn open(path: &Path) -> Result<Self>;
pub fn lock(&self) -> Result<LockFileGuard<'_>>;
pub fn lock_owned(&self) -> Result<OwnedLockFileGuard>;
}
// OPTION 2:
impl FsMutex<T> {
pub fn open(path: &Path, data: T) -> Result<Self>;
pub fn lock(&self) -> Result<LockFileGuard<'_, T>>;
pub fn lock_owned(&self) -> Result<OwnedLockFileGuard<T>>;
}
Also, do you prefer FsMutex, LockFileMutex, FsLockMutex, or....
cc @Diziet
Edited by Nick Mathewson