From 50419ff0e84a39322ec6ff63dadcaede505f0582 Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Wed, 24 Apr 2024 00:29:21 -0700 Subject: [PATCH] interior mutability woes --- src/main.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index d7dd954..3fc2798 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod distance; mod parse; use std::{ + borrow::Borrow, cell::RefCell, collections::{hash_map::Entry, HashMap}, rc::Rc, @@ -34,12 +35,23 @@ impl Node { } } -#[derive(Debug, Clone)] +#[derive(Clone)] struct Destination { - airport: Rc>, + node: Rc>, distance: f64, } +impl std::fmt::Debug for Destination { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let node = self.node.as_ref().borrow(); + + f.debug_struct("Node") + .field("origin", &node.origin) + .field("distance", &self.distance) + .finish() + } +} + impl Destination { fn new(source: &airport::Airport, destination: Rc, graph: &Graph) -> Self { Destination { @@ -47,7 +59,7 @@ impl Destination { (source.lat, source.lon), (destination.lat, destination.lon), ), - airport: graph[&destination.id].clone(), + node: graph[&destination.id].clone(), } } } @@ -116,4 +128,6 @@ fn main() { entry.destinations.push(destination); }; } + + println!("{graph:#?}") }