dancing_droids/src/main.rs

44 lines
872 B
Rust

use std::fs;
use std::io;
enum Orientation {
N,
E,
S,
W,
}
enum Instruction {
L,
R,
F,
}
fn parse_orientation(c: char) -> Result<Orientation, &'static str> {
match c {
'N' => Ok(Orientation::N),
'E' => Ok(Orientation::E),
'S' => Ok(Orientation::S),
'W' => Ok(Orientation::W),
_ => Err("Invalid character, does not match any orientations"),
}
}
fn parse_instruction(c: char) -> Result<Instruction, &'static str> {
match c {
'L' => Ok(Instruction::L),
'R' => Ok(Instruction::R),
'F' => Ok(Instruction::F),
_ => Err("Invalid character, does not match any instructions"),
}
}
fn open_file(filename: &str) -> io::Result<String> {
let content = fs::read_to_string(filename)?;
Ok(content)
}
fn main() {
let conf = open_file("two_robots.txt");
}