From b868ee4d042b8b6a49ec0ad174dda594e4f77788 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Fri, 25 Sep 2020 16:58:30 +0100 Subject: [PATCH] implement formatting for game errors --- src/game.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/game.rs b/src/game.rs index e8887ba..f38d93d 100644 --- a/src/game.rs +++ b/src/game.rs @@ -4,6 +4,8 @@ use std::str::FromStr; use std::collections::HashMap; use std::borrow::BorrowMut; use crate::image::Image; +use std::fmt; +use std::fmt::Display; /// in very early versions of Bitsy, room tiles were defined as single alphanumeric characters - /// so there was a maximum of 36 unique tiles. later versions are comma-separated. @@ -77,6 +79,18 @@ pub enum NotFound { Tile, } +impl Display for NotFound { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f,"Not found: {} data", match self { + &NotFound::Anything => "game", + &NotFound::Avatar => "avatar", + &NotFound::Room => "room", + &NotFound::Sprite => "sprite", + &NotFound::Tile => "tile", + }) + } +} + #[derive(Clone, Debug, PartialEq)] pub struct Game { pub name: String,