Hello! I'm very excited to announce restor
!
restor
is a dynamically typed storage provider. It allows for the allocation of any T:
Any
and insertion of those values. restor
also provides an api for accessing multiple values at the same time using some type mappings as seen in the example.
It also provides multithreaded forms of storage, taking advantage of RwLock
s and Mutex
es.
Lengthy Example:
use restor::{RwLockStorage, make_storage};
use std::thread;
fn main() {
let x = make_storage!(Arc RwLockStorage: String, usize);
x.insert(String::new()).unwrap();
let mut threads = Vec::new();
for i in 0..100 {
let x = x.clone();
let t = thread::spawn(move || {
match x.get::<&mut String>() {
Ok(mut r) => *r = format!("{}{} and ", &*r, i * 20),
Err(_) => {
println!("Thread {} needed to wait", i);
let mut guard = x.waiting_get::<&mut String>().unwrap();
*guard = format!("{}Ack! Waited! {} ", &*guard, i as f32 / 20.);
}
}
while let Err(_) = x.insert::<usize>(i) {}
});
threads.push(t);
}
for t in threads {
t.join().unwrap();
}
let (nums, string) = x.waiting_get::<(&[usize], &String)>().unwrap();
for i in &*nums {
println!("{}", i);
}
println!("string: {}", string);
}
That pretty much shows off the capabilities of the library, except for the run_for
functions.
I've tried to make sure that every thing has at least minimal documentation, and most important functions have an example or two, so suggestions or fixes are definitely welcome and encouraged!
In the past this crate's api has changed quite a bit but I'm hoping to settle on the current api.