Skip to content

Commit

Permalink
Return borrow from present_in
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Carter committed Nov 7, 2020
1 parent 2ba6402 commit 804080e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ pub fn run() -> anyhow::Result<()> {
for file in matches.values_of("FILES").unwrap() {
collect(file, load_file(file)?, &mut root, &mut leaf_nodes);
}
let mut combos: Vec<HashSet<String>> =
leaf_nodes.iter().map(|n| n.borrow().present_in()).collect();
let mut combos: Vec<HashSet<String>> = leaf_nodes
.iter()
.map(|n| n.borrow().present_in().clone())
.collect();
combos.sort_by_key(|s| s.len());
combos.dedup();
combos.reverse();
Expand Down Expand Up @@ -197,10 +199,10 @@ impl Node {
}
}

fn present_in(&self) -> HashSet<String> {
fn present_in(&self) -> &HashSet<String> {
match self {
Self::Leaf { present_in, .. } => present_in.clone(),
Self::Intermediate { present_in, .. } => present_in.clone(),
Self::Leaf { present_in, .. } => &present_in,
Self::Intermediate { present_in, .. } => &present_in,
_ => unreachable!(),
}
}
Expand Down

0 comments on commit 804080e

Please sign in to comment.