Crates.io | guardian |
lib.rs | guardian |
version | 1.2.0 |
source | src |
created_at | 2016-06-21 16:58:29.87826 |
updated_at | 2024-08-06 06:31:51.139037 |
description | Provides owned mutex guards for refcounted mutexes. |
homepage | https://github.com/jonhoo/guardian |
repository | https://github.com/jonhoo/guardian.git |
max_upload_size | |
id | 5445 |
size | 65,041 |
Guardian is a Rust library that provides owned mutex guards for refcounted mutexes.
Normally, lock guards (be it for Mutex
or RwLock
) are bound to the lifetime of the borrow
of the underlying lock. Specifically, the function signatures all resemble:
fn lock<'a>(&'a self) -> Guard<'a>
.
If the mutex is refcounted using an Rc
or an Arc
, it is not necessary for the guard to be
scoped in this way -- it could instead carry with it a ref to the mutex in question, which
allows the guard to be held for as long as is necessary. This is particularly useful for
writing iterators where it is advantageous to hold a read lock for the duration of the
iteration.