Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::sync::{Arc, RwLock, TryLockResult, LockResult, RwLockReadGuard};
- struct CanOnlyReadLock<T> {
- inner: Arc<RwLock<T>>,
- }
- impl<T> CanOnlyReadLock<T> {
- pub fn new(t: T) -> (Arc<RwLock<T>>, Self) {
- let lock = Arc::new(RwLock::new(t));
- let lock2 = lock.clone();
- (lock, Self { inner: lock2 })
- }
- pub fn read(&self) -> LockResult<RwLockReadGuard<T>> {
- self.inner.read()
- }
- pub fn try_read(&self) -> TryLockResult<RwLockReadGuard<T>> {
- self.inner.try_read()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement