pub fn move_to_direction(state: &mut State, direction: Directions) -> NRResult<MoveSuccess> {
    let mut state_ref = state;
    let current_room_id = state_ref.current_room;
    if let Some(current_room) = state_ref
        .rooms
        .iter_mut()
        .find(|room| room.id == current_room_id)
    {
        if let Ok(room_id) = current_room.can_move(direction) {
            state_ref.current_room = room_id;
            Ok(MoveSuccess)
        } else {
            Err(InvalidMovement.into())
        }
    } else {
        Err(NoRoom.into())
    }
}
/// This function is used when the player attempts to move in a direction.
/// If the direction given doesn't exist, then a
/// `ParsingError::InvalidMovement(MoveError::NoExit)` is returned.
/// If the player can move in the direction, then the player's current room
/// is updated and a `ParsingResult::Movement(MoveSuccess)` is returned.
This function is used when the player attempts to move in a direction.
This function is used when the player attempts to move in a direction .
pub fn move_to_direction(state: &mut State, direction: Directions) -> NRResult<MoveSuccess> {
    let mut state_ref = state;
    let current_room_id = state_ref.current_room;
    if let Some(current_room) = state_ref
        .rooms
        .iter_mut()
        .find(|room| room.id == current_room_id)
    {
        if let Ok(room_id) = current_room.can_move(direction) {
            state_ref.current_room = room_id;
            Ok(MoveSuccess)
        } else {
            Err(InvalidMovement.into())
        }
    } else {
        Err(NoRoom.into())
    }
}
pub fn move_to_direction ( state : & mut State , direction : Directions ) -> NRResult < MoveSuccess > { let mut state_ref = state ; let current_room_id = state_ref . current_room ; if let Some ( current_room ) = state_ref . rooms . iter_mut ( ) . find ( | room | room . id == current_room_id ) { if let Ok ( room_id ) = current_room . can_move ( direction ) { state_ref . current_room = room_id ; Ok ( MoveSuccess ) } else { Err ( InvalidMovement . into ( ) ) } } else { Err ( NoRoom . into ( ) ) } }
This function is used when the player attempts to move in a direction.
This function is used when the player attempts to move in a direction .
state
&mut State
direction
Directions
state
&mut State
direction
Directions