From 09d2eaa2e0f7d118793287c6fc113e04ac241785 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Wed, 12 Jun 2024 11:39:21 +0200 Subject: [PATCH] Add method to get selected route from RouteList Signed-off-by: Lee Smet --- mycelium/src/routing_table.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mycelium/src/routing_table.rs b/mycelium/src/routing_table.rs index 5a53668..5a8517b 100644 --- a/mycelium/src/routing_table.rs +++ b/mycelium/src/routing_table.rs @@ -173,6 +173,14 @@ impl RouteList { .map(|(_, e)| e) .find(|entry| entry.neighbour == route_key.neighbour) } + + /// Returns the selected route for the [`Subnet`] this is the `RouteList` for, if one exists. + pub fn selected(&self) -> Option<&RouteEntry> { + self.list + .get(0) + .map(|(_, re)| re) + .and_then(|re| if re.selected { Some(re) } else { None }) + } } /// A guard which allows write access to a single [`RouteEntry`].