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]

Try to lock the given data range.

  • On success: Returns a RangeLockGuard that can be used to access the locked region. Dereferencing RangeLockGuard yields a slice of the data.
  • 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

impl<T: Debug> Debug for RangeLock<T>[src]

impl<T> Sync for RangeLock<T> where
    T: Send
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for RangeLock<T>

impl<T> Send for RangeLock<T> where
    T: Send

impl<T> Unpin for RangeLock<T> where
    T: Unpin

impl<T> UnwindSafe for RangeLock<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.