From 4e4ad1b16e1bd8654c1014c3759710fd91999ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 12 Sep 2021 20:38:33 +0200 Subject: [PATCH] savestate: impl fmt::Display for Error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- savestate/src/error.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/savestate/src/error.rs b/savestate/src/error.rs index ec79f89..7129fcf 100644 --- a/savestate/src/error.rs +++ b/savestate/src/error.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +use std::fmt; use pkstrings::Error as PKStringError; use std::array::TryFromSliceError; use std::io::Error as IOError; @@ -48,3 +49,20 @@ impl From for Error { Error::PKString(err) } } + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match self { + Error::InvalidSaveLength => write!(f, "Invalid save length"), + Error::InvalidChecksum => write!(f, "Invalid checksum"), + Error::InvalidListEnd => write!(f, "Invalid expected end of list"), + Error::InvalidPokemonTypes => write!(f, "Invalid Pokémon Types"), + Error::InvalidPokemonStatus => write!(f, "Invalid Pokémon Status"), + Error::InvalidPokemonMove => write!(f, "Invalid Pokémon Move"), + Error::InvalidPokemonMovePPUp(pp) => write!(f, "Invalid Pokémon PP: {:x?}", pp), + Error::IO(err) => write!(f, "{}", err), + Error::Array(err) => write!(f, "{}", err), + Error::PKString(err) => write!(f, "{}", err), + } + } +}