๐ฟ tendrils
Tendrils is a minimal, ergonomic helper crate for managing shared mutable state in Rust โ built on top of Arc<Mutex<T>> or Arc<RwLock<T>>.
It provides convenient async-ready wrappers, scoped lock helpers, and optional debug metrics via saydbg.
๐ชถ "Lightweight state management for async Rust apps."
โจ Features
โ
Simple and type-safe wrappers around Arc<Mutex<T>> and Arc<RwLock<T>>
โ
Async-ready (tokio or parking_lot)
โ
Scoped access โ locks are automatically dropped before .await
โ
Optional debug metrics integration with [saydbg]
โ
Zero-cost abstraction: you can still access the inner Arc if needed
๐ฆ Installation
Add to your Cargo.toml:
[]
= "0.2"
Optionally enable features:
[]
= { = "0.2", = ["tokio", "saydbg"] }
Available Features
| Feature | Description | Default |
|---|---|---|
tokio |
Use tokio::sync::{Mutex, RwLock} for async contexts |
โ |
parking_lot |
Use parking_lot::{Mutex, RwLock} for sync contexts |
โ |
saydbg |
Enables colorful debug metrics during lock operations | โ |
๐ฑ Quick Start
use Tendrils;
async
๐พ RwTendrils<T> (ReadโWrite variant)
Use this when your state is read frequently and written occasionally.
use RwTendrils;
async
โ๏ธ Helper Functions
Tendrils includes helper functions for direct use with your own state types:
// Scoped synchronous mutation
with_state.await;
// Scoped async mutation
with_state_async.await;
// Non-blocking access
try_with_state;
// For RwLocks
with_state_read.await;
with_state_write.await;
All helpers:
- Acquire and drop locks automatically
- Avoid holding locks across
.awaitpoints - Are backend-agnostic (
tokioorparking_lot)
๐ง Wrapper Types
Tendrils<T>
A minimal wrapper over Arc<Mutex<T>> with ergonomic access methods.
| Method | Description |
|---|---|
new(inner: T) |
Create a new Tendrils from a value |
from_arc(Arc<Mutex<T>>) |
Wrap an existing Arc |
arc() |
Clone the inner Arc<Mutex<T>> |
with(f) |
Lock and mutate synchronously |
with_async(f) |
Async mutation that drops the lock before .await |
try_with(f) |
Non-blocking attempt to mutate |
RwTendrils<T>
A readโwrite wrapper over Arc<RwLock<T>>.
| Method | Description |
|---|---|
new(inner: T) |
Create a new RwTendrils |
read(f) |
Scoped read access |
write(f) |
Scoped write access |
arc() |
Clone the inner Arc<RwLock<T>> |
๐ Using with saydbg (optional)
Enable the saydbg feature to automatically print debug info about lock usage:
[]
= { = "0.1", = ["tokio", "saydbg"] }
Example output:
[debug] Acquiring lock for Tendrils<AppState>
[debug] Released lock for Tendrils<AppState>
Perfect for tracing async lock contention and measuring task flow.
๐งฉ Example: Shared App State
use ;
use Duration;
use sleep;
async
๐ชถ License
Licensed under the MIT License.
๐ก Author
Ryon Boswell โ @crookedlungs
A developer and educator creating lightweight, modular tools for Rust and education.
๐ฆ "Mutate safely. Grow naturally." โ
tendrils