parking_method

Crates.ioparking_method
lib.rsparking_method
version0.4.0
sourcesrc
created_at2022-07-22 16:36:38.257953
updated_at2022-07-22 22:54:46.027726
descriptionObtain parking_lot locks by policy objects
homepage
repositoryhttps://github.com/cehteh/parking_method.git
max_upload_size
id630907
size13,805
(cehteh)

documentation

README

Zero cost abstraction for Locking Methods

'parking_lot' has a lot variants for locking, there is the normal blocking lock, a try_lock, two forms of timed try locks and all of these are available as recursive variant as well.

This leads to a some explosion on the api, dispatching to these variants in generic code becomes pretty bloated. This crate abstracts all the different locking variants into a single trait with a uniform API that takes policy objects for the dispatch on underlying locking methods

Example

// reexports parts of parking_lot as well
use parking_method::*;

let rwlock = RwLock::new(String::from("test"));

// Note the 2 following syntax forms are equivalent
assert_eq!(*Blocking.read(&rwlock).unwrap(), "test");
assert_eq!(*ReadLockMethod::read(&Blocking, &rwlock).unwrap(), "test");

assert_eq!(*TryLock.read(&rwlock).unwrap(), "test");

let timeout = Duration::from_millis(100);

assert_eq!(
    *ReadLockMethod::read(&timeout, &rwlock).unwrap(),
    "test"
);

assert_eq!(
    *ReadLockMethod::read(
        &Recursive(Instant::now() + Duration::from_millis(100)),
        &rwlock).unwrap(),
    "test"
);
Commit count: 7

cargo fmt