我有一个类似RwLock的数据结构。它不是可重入的,但实际上锁定机制是一个const函数。是否有办法将该函数标记为“exclusive_borrow”,而不需要将其更改为可变函数?这样多次调用“read”将在编译时被捕获而不是抛出异常。
struct MyRwLock<T> {
t: T,
}
impl MyRwLock {
// Works fine, but doesn't enforce on compile time that there is
// only 1 Guard.
pub fn read(&self) -> ReadGuard<'_, T> { ... }
// Enforces only 1 ReadGuard at compile time, but unnecessarily
// requires MyMutex to be mutable to read.
pub fn mut_read(&mut self) -> ReadGuard<'_, T> { ... }
}