WarcRwLock
Description
The WarcRwLock 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 RwLock for asynchronous mutation control.
Installation
To use the WarcRwLock crate, add the following dependency to your Cargo.toml:
[]
= "1.0.0"
Example Usage
Here's a simple example of using WarcRwLock:
After applying the #[warcrwlock] attribute, the code is transformed into:
unsafe
unsafe
After using the #[warcrwlock] attribute, the MyStruct will be automatically rewritten with the addition of a base field containing an Arc<RwLock<MyStructBase>>. The functions of MyStruct will then be implemented to safely access the base field.
Method read and write
Similar to the methods in RwLock<T>, these functions are used to lock the usage and gain access to read or write functions, as shown in the example below:
Modules
You can simplify the use of #[warcrwlock] by placing it as an attribute for the module, which will have the same effect as in the previous example:
use warcrwlock;
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 WarcRwLock 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.