← All Workshops

MudEngine Part 7: Save & Load

Step 10 / 17

Re-export RoomInfo and PlayerInfo from messages

RoomInfo and PlayerInfo live in persistence.rs but need to appear in ServerMessage and its State variant, which is defined in messages.rs. Earlier parts defined PlayerInfo right here in messages.rs; now that it is shared with persistence, we move its definition there and re-export it — so all the existing use sites keep working unchanged.

Update src/game/messages.rs to re-export both types and add the rooms field to the State variant.

The re-export is pub use, not just use — the client components import RoomInfo and PlayerInfo from crate::game::messages to type their signals:

mud-engine/src/game/messages.rs
use serde::{Deserialize, Serialize};

pub use super::persistence::{PlayerInfo, RoomInfo};

// ── Shared message types ──

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ClientMessage {
    Move { direction: String },
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ServerMessage {
    State {
        players: Vec<PlayerInfo>,
        your_id: String,
        rooms: Vec<RoomInfo>,
    },
    PlayerJoined(PlayerInfo),
    PlayerMoved(PlayerInfo),
    PlayerLeft {
        id: String,
    },
}
Step 10 / 17