From 4205887223ab26e2950eea74ac1f9df4901695a9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 27 Apr 2020 15:10:26 +0200 Subject: derive Error for ParseBossError The implementation was short, but since we're using thiserror anyway, we might as well be consistent and derive the implementation. --- src/gamedata.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/gamedata.rs b/src/gamedata.rs index 2e6927d..b7ffc11 100644 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -1,6 +1,7 @@ //! This module contains some low-level game data, such as different boss IDs. use num_derive::FromPrimitive; -use std::{fmt, str::FromStr}; +use thiserror::Error; +use std::str::FromStr; /// Enum containing all bosses with their IDs. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, FromPrimitive)] @@ -62,15 +63,10 @@ pub enum Boss { } /// Error for when converting a string to the boss fails. -#[derive(Debug, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, Hash, PartialEq, Eq, Error)] +#[error("Invalid boss identifier: {0}")] pub struct ParseBossError(String); -impl fmt::Display for ParseBossError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Invalid boss identifier: {}", self.0) - } -} - impl FromStr for Boss { type Err = ParseBossError; -- cgit v1.2.3