Merge branch 'martin-dev' into 'master'

Add documentation to main.rs

See merge request mhart/DancingDroids!12
This commit is contained in:
Martin HART 2020-10-18 15:00:53 +02:00
commit c95797d4cf

View File

@ -1,17 +1,21 @@
use std::fs; use std::fs;
use std::io; use std::io;
/// Struct to store robot position
struct Position { struct Position {
x: u32, x: u32,
y: u32, y: u32,
} }
/// A Robot *aka droid* is represented here.
/// Each robot must have a unique id.
struct Robot { struct Robot {
id: u32, id: u32,
o: Orientation, o: Orientation,
p: Position, p: Position,
} }
/// Enum to store all possible orientations.
enum Orientation { enum Orientation {
N, N,
E, E,
@ -19,12 +23,14 @@ enum Orientation {
W, W,
} }
/// Enum to store all possible instructions.
enum Instruction { enum Instruction {
L, L,
R, R,
F, F,
} }
/// Parse char and return corresponding orientation.
fn parse_orientation(c: char) -> Result<Orientation, &'static str> { fn parse_orientation(c: char) -> Result<Orientation, &'static str> {
match c { match c {
'N' => Ok(Orientation::N), '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> { fn parse_instruction(c: char) -> Result<Instruction, &'static str> {
match c { match c {
'L' => Ok(Instruction::L), 'L' => Ok(Instruction::L),
@ -44,13 +51,15 @@ 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> { fn open_file(filename: &str) -> io::Result<String> {
let content = fs::read_to_string(filename)?; let content = fs::read_to_string(filename)?;
Ok(content) Ok(content)
} }
fn main() { fn main() {
let conf = open_file("two_robots.txt"); let mut robot_pool: Vec<Robot> = Vec::new();
let raw_conf = open_file("two_robots.txt");
} }
#[cfg(test)] #[cfg(test)]