From bd662fdd27b7f363458c765b8447883051e45e7a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 27 Jul 2022 23:24:24 +0200 Subject: [PATCH] Introduce 'FenError' enum --- src/fen.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/fen.rs b/src/fen.rs index f112bc9..9c406ef 100644 --- a/src/fen.rs +++ b/src/fen.rs @@ -4,3 +4,21 @@ pub trait FromFen: Sized { fn from_fen(s: &str) -> Result; } + +/// A singular type for all errors that could happen during FEN parsing. +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum FenError { + /// Invalid FEN input. + InvalidFen, +} + +impl std::fmt::Display for FenError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let error_msg = match self { + Self::InvalidFen => "Invalid FEN input", + }; + write!(f, "{}", error_msg) + } +} + +impl std::error::Error for FenError {}