soukoban 0.1.5

A library provides the implementation of some algorithms and data structures related to Sokoban
Documentation
//! Error types.

use thiserror::Error;

/// An error which can be returned when parsing a level.
#[derive(Error, Clone, Eq, PartialEq, Debug)]
pub enum ParseLevelError {
    /// There is a duplicate metadata with the same key.
    #[error("duplicate metadata with key `{0}`")]
    DuplicateMetadata(String),
    /// There is an unterminated block comment.
    #[error("unterminated block comment")]
    UnterminatedBlockComment,
    /// There is no map data.
    #[error("no map data")]
    NoMap,
    /// An error occurred while parsing the map.
    #[error(transparent)]
    ParseMapError(#[from] ParseMapError),
}

/// An error which can be returned when parsing a map.
#[derive(Error, Clone, Eq, PartialEq, Debug)]
pub enum ParseMapError {
    /// There is no player. There should be exactly one player.
    #[error("no player")]
    MissingPlayer,
    /// There are multiple players. There should be exactly one player.
    #[error("more than one player")]
    MultiplePlayers,
    /// The number of boxes and goals do not match. They should be equal.
    #[error("mismatch between number of boxes and goals")]
    BoxGoalMismatch,
    /// At least one box and one goal are required.
    #[error("no box or goal")]
    MissingBoxOrGoal,
    /// Contains non-XSB format character.
    #[error("invalid character: `{0}`")]
    InvalidCharacter(char),
    /// An error occurred during RLE decoding.
    #[error(transparent)]
    DecodeRleError(#[from] DecodeRleError),
    /// Actions are invalid and cannot be used to create level.
    #[error("invalid actions")]
    InvalidActions,
}

/// An error which can be returned when parsing actions.
#[derive(Error, Clone, Eq, PartialEq, Debug)]
pub enum ParseActionsError {
    /// An error which can be returned when parsing a action.
    #[error(transparent)]
    ParseActionError(#[from] ParseActionError),
    /// An error occurred during RLE decoding.
    #[error(transparent)]
    DecodeRleError(#[from] DecodeRleError),
}

/// An error which can be returned when parsing a action.
#[derive(Error, Clone, Eq, PartialEq, Debug)]
pub enum ParseActionError {
    /// Contains non-LURD format character.
    #[error("invalid character: `{0}`")]
    InvalidCharacter(char),
}

/// An error which can be returned when encoding RLE.
#[derive(Error, Clone, Eq, PartialEq, Debug)]
pub enum EncodeRleError {
    /// Encountered an unencodable digital character.
    #[error("digital character encountered: `{0}`")]
    DigitalCharacter(char),
}

/// An error which can be returned when decoding RLE.
#[derive(Error, Clone, Eq, PartialEq, Debug)]
pub enum DecodeRleError {
    /// The decoded string ends with digits.
    #[error("end with digits")]
    EndWithDigits,
    /// An unmatched parenthesis was encountered.
    #[error("unmatched parenthesis")]
    UnmatchedParenthesis,
    /// The length prefix is invalid.
    #[error("invalid length")]
    InvalidLength,
}

/// An error which can be returned when searching for a solution.
#[derive(Error, Clone, Eq, PartialEq, Debug)]
pub enum SearchError {
    /// No solution found.
    #[error("no solution found")]
    NoSolution,
    /// Search was interrupted by user request.
    #[error("search interrupted")]
    Interrupted,
}

/// An error which can be returned when level do/undo/redo actions.
#[derive(Error, Clone, Eq, PartialEq, Debug)]
pub enum ActionError {
    /// Movement in the specified direction is blocked.
    #[error("movement in the specified direction is blocked")]
    MoveBlocked,
    /// Push in the specified direction is blocked.
    #[error("push in the specified direction is blocked")]
    PushBlocked,
    /// No actions available to undo.
    #[error("no actions to undo")]
    NoActions,
    /// No undone actions available to redo.
    #[error("no actions to redo")]
    NoUndoneActions,
}