EasyMutex
EasyMutex is a lightweight, thread-safe, and clonable wrapper around std::sync::Mutex<T> using Arc.
It simplifies shared mutable state management by providing an easy-to-use API for safely reading and writing data across threads, with handy convenience methods and error handling.
Features
- Thread-safe mutable access using
Mutexwrapped in anArc. - Cloneable wrapper for shared ownership.
- All APIs drop the lock before returning, so it should be deadlock free.
- Simple API:
read(),write(),read_result(),write_result(). - Implements
From<T>for ergonomic construction.
Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
Usage
use EasyMutex;
let shared = new;
let clone = shared.clone;
assert_eq!;
clone.write;
assert_eq!;
assert!;
let readed = match shared.read_result ;
assert_eq!;
let data: = "hello".to_string.into;
assert_eq!;
API Overview
EasyMutex::new(value)— Create a new EasyMutex.read()— Acquire lock and clone the value. Panics if poisoned.write(value)— Acquire lock and replace the value. Panics if poisoned.read_safe()/write_safe(value)— Return Result with poison error info.From<T>implemented for convenient construction via.into().
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Licensing
All contributions to this project are licensed under the terms of the Apache License, Version 2.0.
By contributing, you agree that your code will be released under the same license.