Armc is a Rust library that provides a wrapper for shared data, ensuring data integrity and thread-blocking during modifications and reads.
You can add the Armc dependency to your Cargo.toml file:
yaml
[dependencies]
armc = "1.4.4"
To use the library, simply import it with the following code:
rust
use armc::Armc;
Below are some of the library's features:
To create an Armc object, simply use the new method and pass the data you want to store:
rust
let armc = Armc::new(5);
Accessing the data of an Armc object
You can access the stored data by blocking possible mutations. Multiple accesses can be done in parallel.
rust
let data = armc.lock_ref();
println!("Data: {:?}", data);
Modifying data of an Armc object
To modify the data of an Armc object, you need to use the lock method, which will block all mutation accesses:
rust
let mut data = armc.lock();
*data = 10;
println!("Data: {:?}", data);
You can clone an Armc object using the clone method:
rust
let armc_clone = armc.clone();
println!("Data: {:?}", *armc_clone.lock_ref());
object!
and its derivativesOne set of macros that might be useful for Rust programmers are the object!
, object_with_new!
, object_ref_access!
, and object_mut_access!
macros. These macros are designed to simplify the creation of structs with thread-safe access to their fields.
The object!
macro creates a struct with fields wrapped in an ARMC (Atomic Reference-Counting Mutex) to allow thread-safe mutation. The macro retains the name of the macro for the name of the struct.
The object_with_new!
macro is similar to the object!
macro, but it also generates a constructor method named new
that takes in the initial values for each field.
The object_ref_access!
macro is similar to the object_with_new!
macro, but it also generates getter methods for each field.
The object_mut_access!
macro is similar to the object_ref_access!
macro, but it also generates mutable setter methods for each field with the suffix _mut
.
These macros are designed to save time and effort when creating structs with thread-safe access to their fields, and can be used in the following way:
```rust
extern crate my_crate;
objectmutaccess!(MyStruct { foo: u32, bar: String, });
let mut mystruct = MyStruct::new(42, "hello".tostring());
asserteq!(*mystruct.foo(), 42);
mystruct.foomut(13); asserteq!(*mystruct.foo(), 13); ```
For more information on the implementation of these macros, see the documentation for each individual macro.
Contributions are welcome! Feel free to open an issue or submit a pull request.