arc_map 0.1.1

A Map of Arc<Mutex<V>> that eases the access of indivdual members
Documentation

The ArcMap exists to enable multiple Mutex based Elements in a Map to be accessible

without the need for locking the whole HashMap, while you access one element.

Instead the Map is hidden inside a thread, that will return accesible elements as requested.

Rather than limit the access within the fn it seemed simple to return the Arc directly.

Though because the Map may not contain the required element, and becuase of thread send/recieve. The get method returns a "Result<Arc<Mutex>,AMapErr>"

This can be accessed as follows : (Though normally for more complex objects)

use arc_map::ArcMap;
let mut am = ArcMap::new();

//update by grabbing mutex  
am.insert(3,"hello".to_string());
{
    let p = am.get(3).unwrap(); //p is Arc<Mutex<String>>
    let mut s = p.lock().unwrap();
    s.push_str(" world");
}

//read by grabbing mutex 
{ 
    let p2 = am.get(3).unwrap();
    let s2 = p2.lock().unwrap();
    assert_eq!(*s2,"hello world".to_string());
}


am.insert(4,"goodbye".to_string());

//update in place (No need for scoping)
am.on_do(4,|mut s| (&mut s).push_str(" cruel world")).unwrap();

//get info out
let ls = am.on_do(4,|s| s.clone()).unwrap();

assert_eq!(&ls,"goodbye cruel world");

While this can be achieved using traditional mutex locks, the interface here is much simpler to use.