diff --git a/src/action.rs b/src/action.rs index 6358cf3..e0b510c 100644 --- a/src/action.rs +++ b/src/action.rs @@ -1,14 +1,30 @@ +//! An action. + use std::fmt; use crate::{direction::Direction, error::ParseActionError}; +/// Represents an action. #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub enum Action { + /// Move action in a specified direction. Move(Direction), + /// Push action in a specified direction. Push(Direction), } impl Action { + /// Returns the direction associated with the action. + /// + /// # Examples + /// + /// ``` + /// use soukoban::direction::Direction; + /// use soukoban::Action; + /// + /// let action = Action::Move(Direction::Up); + /// assert_eq!(action.direction(), Direction::Up); + /// ``` pub fn direction(&self) -> Direction { match *self { Action::Move(direction) => direction, @@ -16,10 +32,32 @@ impl Action { } } + /// Checks if the action is a move action. + /// + /// # Examples + /// + /// ``` + /// use soukoban::direction::Direction; + /// use soukoban::Action; + /// + /// let action = Action::Move(Direction::Up); + /// assert!(action.is_move()); + /// ``` pub fn is_move(&self) -> bool { matches!(&self, Action::Move(_)) } + /// Checks if the action is a push action. + /// + /// # Examples + /// + /// ``` + /// use soukoban::direction::Direction; + /// use soukoban::Action; + /// + /// let action = Action::Push(Direction::Up); + /// assert!(action.is_push()); + /// ``` pub fn is_push(&self) -> bool { matches!(&self, Action::Push(_)) } diff --git a/src/lib.rs b/src/lib.rs index 872b602..95a57b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ #![deny(missing_docs)] #![doc = include_str!("../README.md")] +pub mod action; pub mod actions; pub mod deadlock; pub mod direction; @@ -13,9 +14,9 @@ pub mod run_length; pub mod solver; pub mod tiles; -mod action; mod state; +pub use action::*; pub use actions::*; pub use error::*; pub use level::*;