WarcMutex
Description
The WarcMutex crate is a Rust library that provides a macro attribute for mods, structs, and impls. The purpose of this library is to generate a wrapper that allows the struct to be used with the asynchronous reference control called Arc and the Mutex for asynchronous mutation control.
Installation
To use the WarcMutex crate, add the following dependency to your Cargo.toml
:
[]
= "1.0.0"
Example Usage
Here's a simple example of using WarcMutex:
After applying the #[warcmutex]
attribute, the code is transformed into:
unsafe
unsafe
After using the #[warcmutex]
attribute, the MyStruct
will be automatically rewritten with the addition of a base
field containing an Arc<Mutex<MyStructBase>>
. The functions of MyStruct
will then be implemented to safely access the base
field.
Method lock
Similar to the method in Mutex<T>
, this function is used to lock the usage and gain access to functions that return references as shown in the example below:
Modules
You can simplify the use of #[warcmutex]
by placing it as an attribute for the module, which will have the same effect as in the previous example:
use warcmutex;
When used on a module, all structs, impls, and mods will be included, with exceptions.
The use of the attribute may not work well with other attributes.
Contribution
The WarcMutex project is mainly maintained by a single developer known as PFP but welcomes contributions from the community. However, it's essential that contributions stay within the scope of the project's main function.
License
This project is licensed under the MIT License. See the LICENSE file for more details.