savestate: impl fmt::Display for Error

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-09-12 20:38:33 +02:00
parent 11e54ded8b
commit 4e4ad1b16e
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -13,6 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::fmt;
use pkstrings::Error as PKStringError;
use std::array::TryFromSliceError;
use std::io::Error as IOError;
@ -48,3 +49,20 @@ impl From<PKStringError> 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),
}
}
}