Expand description
§🌿 tendrils
Tiny, flexible helpers for managing shared state safely in async Rust.
§✨ Features
tokio(default): asyncMutex/RwLocksupportparking_lot: lightweight syncMutex/RwLocktrace: adds tracing spans to lock usagemetrics: logs lock duration (usessaydbg)
§Example
use tendrils::with_state;
use std::sync::Arc;
use tokio::sync::Mutex;
#[derive(Default)]
struct AppState { count: u32 }
type Shared = Arc<Mutex<AppState>>;
#[tokio::test]
async fn main() {
let state: Shared = Arc::new(Mutex::new(AppState::default()));
with_state(&state, |s| {
s.count += 1;
println!("Count = {}", s.count);
}).await;
}Structs§
- RwTendrils
- A small, ergonomic handle for shared state that is often read and occasionally written:
wraps
Arc<RwLock<T>>. - Tendrils
- A small, ergonomic handle for shared mutable state:
wraps
Arc<Mutex<T>>(Tokio or parking_lot depending on features).
Functions§
- try_
with_ state - Attempts to lock a
Mutexand execute a closure without blocking. - with_
state - Executes a synchronous closure inside a locked
Arc<Mutex<T>>. - with_
state_ async - Executes an async closure inside a locked
Arc<Mutex<T>>, ensuring the lock is dropped before awaiting the future. - with_
state_ read - Executes a read-only closure inside a locked
Arc<RwLock<T>>. - with_
state_ write - Executes a write closure inside a locked
Arc<RwLock<T>>.