pub-issues
This commit is contained in:
parent
7c935269f5
commit
83cbb0094e
18
src/robot.rs
18
src/robot.rs
@ -1,19 +1,19 @@
|
|||||||
/// A Robot *aka droid* is represented here.
|
/// A Robot *aka droid* is represented here.
|
||||||
/// Each robot must have a unique id.
|
/// Each robot must have a unique id.
|
||||||
pub struct Robot {
|
pub struct Robot {
|
||||||
id: u32,
|
pub id: u32,
|
||||||
o: Orientation,
|
pub o: Orientation,
|
||||||
p: Position,
|
pub p: Position,
|
||||||
i: Vec<char>,
|
i: Vec<char>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Robot {
|
impl Robot {
|
||||||
/// Create new `Robot` with given id, `Orientation`, `Position` and instructions.
|
/// Create new `Robot` with given id, `Orientation`, `Position` and instructions.
|
||||||
fn new(id: u32, o: Orientation, p: Position, i: Vec<char>) -> Robot {
|
pub fn new(id: u32, o: Orientation, p: Position, i: Vec<char>) -> Robot {
|
||||||
Robot { id, o, p, i }
|
Robot { id, o, p, i }
|
||||||
}
|
}
|
||||||
/// Apply given instruction to a `Robot`.
|
/// Apply given instruction to a `Robot`.
|
||||||
fn execute_instruction(&mut self) {
|
pub fn execute_instruction(&mut self) {
|
||||||
match self.i.pop() {
|
match self.i.pop() {
|
||||||
Some(instruction) => match instruction {
|
Some(instruction) => match instruction {
|
||||||
'L' => match self.o {
|
'L' => match self.o {
|
||||||
@ -42,7 +42,7 @@ impl Robot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Enum to store all possible orientations.
|
/// Enum to store all possible orientations.
|
||||||
enum Orientation {
|
pub enum Orientation {
|
||||||
N,
|
N,
|
||||||
E,
|
E,
|
||||||
S,
|
S,
|
||||||
@ -51,9 +51,9 @@ enum Orientation {
|
|||||||
|
|
||||||
/// Struct to store robot position.
|
/// Struct to store robot position.
|
||||||
#[derive(PartialEq, Eq, Hash)]
|
#[derive(PartialEq, Eq, Hash)]
|
||||||
struct Position {
|
pub struct Position {
|
||||||
x: i32,
|
pub x: i32,
|
||||||
y: i32,
|
pub y: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user