Skip to content

Commit

Permalink
docs: add documentation for 'Action'
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenMian committed May 18, 2024
1 parent 6c01179 commit d7ceb3d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,63 @@
//! 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,
Action::Push(direction) => direction,
}
}

/// 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(_))
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![deny(missing_docs)]
#![doc = include_str!("../README.md")]

pub mod action;
pub mod actions;
pub mod deadlock;
pub mod direction;
Expand All @@ -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::*;
Expand Down

0 comments on commit d7ceb3d

Please sign in to comment.