use gametools::ordering::MinPriorityQ;
fn main() {
let mut attack_order = MinPriorityQ::new();
println!("Building the fleet...");
let attackers = build_fleet();
println!("Organizing the fleet...");
for unit in attackers {
let time_to_target = unit.distance / unit.speed;
attack_order.push(unit, time_to_target);
}
println!("Starting attack!");
while let Some((attacker, ttt)) = attack_order.pop() {
println!(" → {:<10} ({} min to target)", attacker.name, ttt);
}
}
fn build_fleet<'a>() -> Vec<NavalUnit<'a>> {
vec![
NavalUnit::from(("Fast Boat", 40, 10)),
NavalUnit::from(("Cruiser", 30, 5)),
NavalUnit::from(("Tugboat", 10, 2)),
NavalUnit::from(("Submarine", 48, 8)),
]
}
#[derive(Debug, Clone)]
struct NavalUnit<'a> {
name: &'a str,
distance: u64,
speed: u64,
}
impl<'a> From<(&'a str, u64, u64)> for NavalUnit<'a> {
fn from((name, distance, speed): (&'a str, u64, u64)) -> Self {
Self {
name,
distance,
speed,
}
}
}