Struct range_lock::RangeLock [−][src]
pub struct RangeLock<T> { /* fields omitted */ }
Multi-thread range lock for Vec<T>
.
Example
use range_lock::RangeLock; use std::sync::Arc; let lock = Arc::new(RangeLock::new(vec![1, 2, 3, 4, 5])); let mut guard = lock.try_lock(2..4).expect("Failed to lock 2..4"); assert_eq!(guard[0], 3); guard[0] = 100; assert_eq!(guard[0], 100); assert_eq!(guard[1], 4);
Implementations
impl<'a, T> RangeLock<T>
[src]
pub fn new(data: Vec<T>) -> RangeLock<T>
[src]
Construct a new RangeLock.
data
: The data Vec to protect.
pub fn into_inner(self) -> Vec<T>
[src]
Unwrap the RangeLock into the contained data. This method consumes self.
pub fn try_lock(
&'a self,
range: impl RangeBounds<usize>
) -> TryLockResult<RangeLockGuard<'a, T>>
[src]
&'a self,
range: impl RangeBounds<usize>
) -> TryLockResult<RangeLockGuard<'a, T>>
Try to lock the given data range
.
- On success: Returns a
RangeLockGuard
that can be used to access the locked region. DereferencingRangeLockGuard
yields a slice of thedata
. - On failure: Returns TryLockError::WouldBlock, if the range is contended. The locking attempt may be retried by the caller upon contention. Returns TryLockError::Poisoned, if the lock is poisoned.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for RangeLock<T>
impl<T> Send for RangeLock<T> where
T: Send,
T: Send,
impl<T> Unpin for RangeLock<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for RangeLock<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,