From de406aba7017d9041d15708c009f99719f25fdf3 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Thu, 9 Dec 2021 10:55:53 -0800 Subject: [PATCH] Fix #56 - Drop unneeded mut from Dijkstra::get_distance While here, drop an unnecessary bare `Option::unwrap()`. --- src/iterators/dijkstra.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/iterators/dijkstra.rs b/src/iterators/dijkstra.rs index 0bae8b5..ef69b37 100644 --- a/src/iterators/dijkstra.rs +++ b/src/iterators/dijkstra.rs @@ -119,16 +119,12 @@ impl<'a, T> Dijkstra<'a, T> { Ok(VertexIter(Box::new(iter::empty()))) } - pub fn get_distance(&mut self, vert: &'a VertexId) -> Result { + pub fn get_distance(&self, vert: &'a VertexId) -> Result { if self.iterable.fetch(vert).is_none() { return Err(GraphErr::NoSuchVertex); } - if self.distances.contains_key(vert) { - return Ok(*self.distances.get(vert).unwrap()); - } - - Ok(f32::MAX) + Ok(self.distances.get(vert).copied().unwrap_or(f32::MAX)) } fn calc_distances(&mut self) {