sokoban-elements 0.2.1

Parsing and writing Sokoban, Hexoban, Trioban and Octoban file formats.
Documentation
/// `true` if the line is empty or contains only whitespace characters.
pub(crate) fn is_blank(line: &str) -> bool { line.chars().all(char::is_whitespace) }

/// x coordinate of a 1D index in a 2D array with the given width.
#[inline(always)]
pub(crate) fn index_x(position: usize, width: usize) -> usize { position % width }

/// y coordinate of a 1D index in a 2D array with the given width.
#[inline(always)]
pub(crate) fn index_y(position: usize, width: usize) -> usize { position / width }

/// `Some(index)` if `(x, y)` is a valid coordinate in a 2D array with the given width,
#[inline(always)]
pub(crate) fn checked_index_1d(x: usize, y: usize, width: usize) -> Option<usize> {
    // y * width + x
    y.checked_mul(width)?.checked_add(x)
}

/// Similar to [`checked_index_1d()`], saturating at `usize::MAX` if the result would overflow so it
/// always returns a value and not and `Option`.
#[inline(always)]
pub(crate) fn saturating_index_1d(x: usize, y: usize, width: usize) -> usize {
    // y * width + x
    y.saturating_mul(width).saturating_add(x)
}