diff --git a/src/layout.rs b/src/layout.rs index 03686d21a4f507211ff93303b168d7c487993f2b..78badce40ef00e9ecd3046ba6eafe426d8f37a02 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1,4 +1,4 @@ -use std::fmt::{write, Debug, Formatter}; +use std::fmt::{Debug, Formatter}; use crate::utils::IntoTile; /// The size of the grid that can be matched; equal to the length of one side of the square grid @@ -11,7 +11,7 @@ const GRID_CENTER: usize = (TILE_GRID_SIZE - 1) / 2; #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub struct NotSquareError; impl std::fmt::Display for NotSquareError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "Input is not a square grid") } } @@ -149,7 +149,7 @@ impl Debug for TileLayout { } } -impl <T> TryFrom<&[T]> for TileLayout where T: IntoTile + Copy + Default + Debug { +impl <T> TryFrom<&[T]> for TileLayout where T: IntoTile + Copy + Default { type Error = NotSquareError; fn try_from(value: &[T]) -> Result<Self, Self::Error> { if is_square(value.len()) { @@ -213,11 +213,7 @@ impl TileMatcher { /// Load data from an LDTK JSON file. Supports arbitrary sized matchers for any square grid. /// Other sizes of matcher will result in `None` pub fn from_ldtk_array(value: Vec<i64>) -> Option<Self> { - if is_square(value.len()) { - Some(Self(transpose(value.as_slice()).map(TileStatus::from))) - } else { - None - } + Self::try_from(value.as_slice()).ok() } }