Add documentation to main.rs

This commit is contained in:
mhart 2020-10-17 18:16:40 +02:00
parent 5ea2024e31
commit 8508c53bef
1 changed files with 8 additions and 0 deletions

View File

@ -1,17 +1,21 @@
use std::fs;
use std::io;
/// Struct to store robot position
struct Position {
x: u32,
y: u32,
}
/// A Robot *aka droid* is represented here.
/// Each robot must have a unique id.
struct Robot {
id: u32,
o: Orientation,
p: Position,
}
/// Enum to store all possible orientations.
enum Orientation {
N,
E,
@ -19,12 +23,14 @@ enum Orientation {
W,
}
/// Enum to store all possible instructions.
enum Instruction {
L,
R,
F,
}
/// Parse char and return corresponding orientation.
fn parse_orientation(c: char) -> Result<Orientation, &'static str> {
match c {
'N' => Ok(Orientation::N),
@ -35,6 +41,7 @@ fn parse_orientation(c: char) -> Result<Orientation, &'static str> {
}
}
/// Parse char and return corresponding instruction.
fn parse_instruction(c: char) -> Result<Instruction, &'static str> {
match c {
'L' => Ok(Instruction::L),
@ -44,6 +51,7 @@ fn parse_instruction(c: char) -> Result<Instruction, &'static str> {
}
}
/// Retrieve the content of a file and return it as a string.
fn open_file(filename: &str) -> io::Result<String> {
let content = fs::read_to_string(filename)?;
Ok(content)