Stage 2

move clone and locking to functions on tasklist

impl  TaskList {
	pub fn new() -> TaskList {
		TaskList {
			tasks : Arc::new(RwLock::new(TaskHashMap::new())),
		}
	}

	pub fn readable(self) -> RwLockReadGuard<TaskHashMap>{
		let tl =  self.tasks.clone();
		let mut my_tasks = tl.read().expect("RWLOCK poisoned");	
		my_tasks
	}

	pub fn writable(self) -> RwLockWriteGuard<TaskHashMap>{
		let tl =  self.tasks.clone();
		let mut my_tasks = tl.write().expect("RWLOCK poisoned");	
		my_tasks
	}
}


	pub fn readable<'rwlock>(self) -> RwLockReadGuard<'rwlock,TaskHashMap>{
		let tl =  self.tasks.clone();
		let my_tasks = tl.read().expect("RWLOCK poisoned");	
		my_tasks
	}

	pub fn writable<'rwlock>(self) -> RwLockWriteGuard<'rwlock,TaskHashMap>{
		let tl =  self.tasks.clone();
		let my_tasks = tl.write().expect("RWLOCK poisoned");	
		my_tasks
	}

   Compiling playground v0.0.1 (/playground)
error[E0515]: cannot return value referencing local variable `tl`
  --> src/lib.rs:28:3
   |
27 |         let my_tasks = tl.read().expect("RWLOCK poisoned");    
   |                        -- `tl` is borrowed here
28 |         my_tasks
   |         ^^^^^^^^ returns a value referencing data owned by the current function

Seems like a similar issue seen by this user in the error and that what I wanted to do wouldn’t be possible : https://users.rust-lang.org/t/returning-a-value-from-inside-a-cloned-arc-t/6903/3

Back to index page of the project is about getting the initial rust API running.