fn extract_movement(state: &State, command_tokens: &[String]) -> Option<Directions> {
    let movements = state.config.allowed_movements.movements.clone();
    let directions = state.config.allowed_directions.directions.clone();
    match command_tokens.len() {
        1 => match &command_tokens[0][..] {
            "north" | "n" => Some(Directions::North),
            "south" | "s" => Some(Directions::South),
            "east" | "e" => Some(Directions::East),
            "west" | "w" => Some(Directions::West),
            _ => None,
        },
        2 => {
            if movements.contains(&command_tokens[0]) && directions.contains(&command_tokens[1]) {
                match &command_tokens[1][..] {
                    "north" | "n" => Some(Directions::North),
                    "south" | "s" => Some(Directions::South),
                    "east" | "e" => Some(Directions::East),
                    "west" | "w" => Some(Directions::West),
                    _ => None,
                }
            } else {
                None
            }
        }
        _ => None,
    }
}
// This should be re-worked to use events instead. Maybe v2.0
// Using events allows for commands such "sneak north" to get
// past a sleeping dragon, or a corporate goon standing guard.
// As it stands, the parser is very simple when it comes to mo-
// ving around.
This should be re-worked to use events instead. Maybe v2.0
Using events allows for commands such "sneak north" to get
past a sleeping dragon, or a corporate goon standing guard.
As it stands, the parser is very simple when it comes to mo
ving around.
This should be re - worked to use events instead . Maybe v2 . 0 Using events allows for commands such " sneak north " to get past a sleeping dragon or a corporate goon standing guard . As it stands the parser is very simple when it comes to mo ving around .
fn extract_movement(state: &State, command_tokens: &[String]) -> Option<Directions> {
    let movements = state.config.allowed_movements.movements.clone();
    let directions = state.config.allowed_directions.directions.clone();
    match command_tokens.len() {
        1 => match &command_tokens[0][..] {
            "north" | "n" => Some(Directions::North),
            "south" | "s" => Some(Directions::South),
            "east" | "e" => Some(Directions::East),
            "west" | "w" => Some(Directions::West),
            _ => None,
        },
        2 => {
            if movements.contains(&command_tokens[0]) && directions.contains(&command_tokens[1]) {
                match &command_tokens[1][..] {
                    "north" | "n" => Some(Directions::North),
                    "south" | "s" => Some(Directions::South),
                    "east" | "e" => Some(Directions::East),
                    "west" | "w" => Some(Directions::West),
                    _ => None,
                }
            } else {
                None
            }
        }
        _ => None,
    }
}
fn extract_movement ( state : & State , command_tokens : & [ String ] ) -> Option < Directions > { let movements = state . config . allowed_movements . movements . clone ( ) ; let directions = state . config . allowed_directions . directions . clone ( ) ; match command_tokens . len ( ) { 1 => match & command_tokens [ 0 ] [ .. ] { " " | " " => Some ( Directions :: North ) , " " | " " => Some ( Directions :: South ) , " " | " " => Some ( Directions :: East ) , " " | " " => Some ( Directions :: West ) , _ => None , } , 2 => { if movements . contains ( & command_tokens [ 0 ] ) && directions . contains ( & command_tokens [ 1 ] ) { match & command_tokens [ 1 ] [ .. ] { " " | " " => Some ( Directions :: North ) , " " | " " => Some ( Directions :: South ) , " " | " " => Some ( Directions :: East ) , " " | " " => Some ( Directions :: West ) , _ => None , } } else { None } } _ => None , } }
This should be re-worked to use events instead.
This should be re - worked to use events instead .
state
&State
command_tokens
&[String]
state
&State
command_tokens
&[String]