interior mutability woes

main
Zynh0722 2024-04-24 00:29:21 -07:00
parent bc2f900f37
commit 50419ff0e8
1 changed files with 17 additions and 3 deletions

View File

@ -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<RefCell<Node>>,
node: Rc<RefCell<Node>>,
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<airport::Airport>, 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:#?}")
}