diff --git a/tree/src/lib.rs b/tree/src/lib.rs index 4cfef40..7341b7f 100644 --- a/tree/src/lib.rs +++ b/tree/src/lib.rs @@ -27,7 +27,7 @@ impl Tree { } /// Use a breadth-first-search pattern to find a node, returning the node if found. - pub fn find_bfs<'a, F>(&'a self, op: F) -> Option> + pub fn find_bfs(&self, op: F) -> Option> where F: FnOnce(&T) -> bool + Copy, { @@ -84,14 +84,15 @@ impl Node { }))) } - // I am copying the value because I don't have a mechanism for keeping the borrow ref active. - // My next step is to figure out how to keep the borrow ref active so that I don't have to - // clone the item. Then I could drop the Clone constraint. - pub fn value<'a>(&'a self) -> Ref { + /// Immutably retrieve the data in this node. + pub fn value<'a>(&self) -> Ref { + // Ref::map is not actually a member function. I don't know why this was done, other than + // maybe to avoid conflicting with other `map` declarations. Why that is necessary when + // Option::map exists as a member, I don't know. Ref::map(self.0.borrow(), |v| &v.value) } - pub fn children<'a>(&'a self) -> Ref>> { + pub fn children<'a>(&self) -> Ref>> { Ref::map(self.0.borrow(), |v| &v.children) }