From 8508c53befdf0e0ef81e820a9a5f7256f8e0186c Mon Sep 17 00:00:00 2001 From: mhart Date: Sat, 17 Oct 2020 18:16:40 +0200 Subject: [PATCH 1/3] Add documentation to main.rs --- src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.rs b/src/main.rs index 48fdae4..f13144f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { match c { 'N' => Ok(Orientation::N), @@ -35,6 +41,7 @@ fn parse_orientation(c: char) -> Result { } } +/// Parse char and return corresponding instruction. fn parse_instruction(c: char) -> Result { match c { 'L' => Ok(Instruction::L), @@ -44,6 +51,7 @@ fn parse_instruction(c: char) -> Result { } } +/// Retrieve the content of a file and return it as a string. fn open_file(filename: &str) -> io::Result { let content = fs::read_to_string(filename)?; Ok(content) From bd89bfa744af57e089c4ae76a99ec2e16f8b3536 Mon Sep 17 00:00:00 2001 From: mhart Date: Sat, 17 Oct 2020 21:05:06 +0200 Subject: [PATCH 2/3] Add Vec to store all the robots --- src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.rs b/src/main.rs index f13144f..9600ecd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,7 @@ fn open_file(filename: &str) -> io::Result { } fn main() { + let mut robot_pool: Vec = Vec::new(); let conf = open_file("two_robots.txt"); } From a55a4935ac968c9ac4e334e3c935620abe56de5c Mon Sep 17 00:00:00 2001 From: mhart Date: Sat, 17 Oct 2020 21:17:36 +0200 Subject: [PATCH 3/3] Rename conf to raw_conf, conf will be the parsed configuration String --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9600ecd..a362e2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,7 +59,7 @@ fn open_file(filename: &str) -> io::Result { fn main() { let mut robot_pool: Vec = Vec::new(); - let conf = open_file("two_robots.txt"); + let raw_conf = open_file("two_robots.txt"); } #[cfg(test)]