From d99b3d49e0758b5de3bf837462a6287097d07910 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 22 Oct 2022 19:14:03 +0200 Subject: [PATCH] Refactor changing data --- brood/src/commands/path.rs | 4 ++-- brood/src/data.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/brood/src/commands/path.rs b/brood/src/commands/path.rs index 2e2ca74..efe4dc7 100644 --- a/brood/src/commands/path.rs +++ b/brood/src/commands/path.rs @@ -83,8 +83,8 @@ fn dijkstra( ) -> Option> { println!("> Prepare state"); let mut data = data - .change_page_data(&DijkstraPageInfo::from_page_info) - .change_link_data(&DijkstraLinkInfo::from_link_info); + .change_page_data(DijkstraPageInfo::from_page_info) + .change_link_data(DijkstraLinkInfo::from_link_info); let mut queue = BinaryHeap::new(); data.page_mut(from_idx).data.cost = 0; queue.push(Entry::new(0, from_idx)); diff --git a/brood/src/data.rs b/brood/src/data.rs index 05ded17..f6e86ea 100644 --- a/brood/src/data.rs +++ b/brood/src/data.rs @@ -94,7 +94,7 @@ impl Page { } impl

Page

{ - pub fn change_data(self, f: &impl Fn(P) -> P2) -> Page { + pub fn change_data(self, f: impl Fn(P) -> P2) -> Page { Page { link_idx: self.link_idx, data: f(self.data), @@ -136,7 +136,7 @@ impl Link { } impl Link { - pub fn change_data(self, f: &impl Fn(L) -> L2) -> Link { + pub fn change_data(self, f: impl Fn(L) -> L2) -> Link { Link { to: self.to, data: f(self.data), @@ -240,7 +240,7 @@ impl AdjacencyList { &mut self.links[idx as usize] } - pub fn change_page_data(self, page_f: &impl Fn(P) -> P2) -> AdjacencyList { + pub fn change_page_data(self, page_f: impl Fn(P) -> P2 + Copy) -> AdjacencyList { let pages = self .pages .into_iter() @@ -253,7 +253,7 @@ impl AdjacencyList { } } - pub fn change_link_data(self, link_f: &impl Fn(L) -> L2) -> AdjacencyList { + pub fn change_link_data(self, link_f: impl Fn(L) -> L2 + Copy) -> AdjacencyList { let links = self .links .into_iter()