impl Display for tintin room and exit

master
rascul 3 years ago
parent 73b2f1421f
commit e298494dc8

@ -103,22 +103,11 @@ fn main() -> Result<(), Box<dyn Error>> {
tintin_rooms.insert(tintin_room.vnum, tintin_room); tintin_rooms.insert(tintin_room.vnum, tintin_room);
} }
for (vnum, room) in tintin_rooms { for (_vnum, room) in tintin_rooms {
println!("{}", room); println!("{}", room);
for exit in room.exits { for exit in room.exits {
println!( println!("{}", exit);
"E {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}}",
exit.vnum,
exit.name,
exit.cmd,
exit.dir,
exit.flags,
exit.data,
exit.weight,
exit.color,
exit.decay
);
} }
println!(); println!();

@ -1,3 +1,5 @@
use std::fmt;
#[derive(Debug)] #[derive(Debug)]
pub struct Exit { pub struct Exit {
/// vnum /// vnum
@ -27,3 +29,21 @@ pub struct Exit {
/// decay? /// decay?
pub decay: f64, pub decay: f64,
} }
impl fmt::Display for Exit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"E {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}}",
&self.vnum,
&self.name,
&self.cmd,
&self.dir,
&self.flags,
&self.data,
&self.weight,
&self.color,
&self.decay
)
}
}

Loading…
Cancel
Save