I am building a concurrent BTree and I'm struggling with figuring out how to create a stack of latches (RwLockWriteGuard). I built this simple example that takes in a node, and returns both the node and a guard. I'm getting the following error:
cannot return value referencing local data `node_option.0`
returns a value referencing data owned by the current function`
I'm pretty sure it's because the write_guard
has a reference to the node_option
. How might I be able to return both elements in the same function? Here is the simplified version of the code:
struct Node {
lock: RwLock<()>,
}
fn return_lock<'a>(node_option: Option<Node>) -> (Option<Node>, RwLockWriteGuard<'a, ()>) {
match node_option {
Some(ref node) => {
let write_guard = node.lock.write().unwrap();
return (node_option, write_guard);
}
None => todo!(),
};
}