From 7e23cb8f777d7c0b50df3c874109f52ef78822bd Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 27 Jul 2022 23:24:24 +0200 Subject: [PATCH] Introduce 'Error' enum --- src/build.rs | 1 + src/error.rs | 16 ++++++++++++++++ src/lib.rs | 1 + 3 files changed, 18 insertions(+) create mode 100644 src/error.rs diff --git a/src/build.rs b/src/build.rs index 10d7a94..c0bcdc6 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,6 +1,7 @@ use std::io::{Result, Write}; pub mod board; +pub mod error; pub mod movegen; pub mod utils; diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..535bd7b --- /dev/null +++ b/src/error.rs @@ -0,0 +1,16 @@ +/// A singular type for all errors that could happen when using this library. +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub enum Error { + InvalidFen, +} + +impl std::fmt::Display for Error { + 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 Error {} diff --git a/src/lib.rs b/src/lib.rs index bfcf0bd..c1b793f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod board; +pub mod error; pub mod movegen; pub mod utils;