Moved Digimon's errors to their own module.

This commit is contained in:
2020-09-20 00:34:08 +01:00
parent aa7edaf92b
commit a4eba109bf
2 changed files with 101 additions and 94 deletions

View File

@@ -1,15 +1,18 @@
#![doc(include = "digimon.md")]
// Modules
pub mod error;
// Exports
pub use error::{FromBytesError, ToBytesError};
// Imports
use crate::{
game::{
card::property::{self, ArrowColor, CrossMoveEffect, Effect, EffectCondition, Level, Move, Speciality},
card::property::{ArrowColor, CrossMoveEffect, Effect, EffectCondition, Level, Move, Speciality},
Bytes,
},
util::{
array_split, array_split_mut,
null_ascii_string::{self, NullAsciiString},
},
util::{array_split, null_ascii_string::NullAsciiString, array_split_mut},
AsciiStrArr,
};
use byteorder::{ByteOrder, LittleEndian};
@@ -93,95 +96,6 @@ pub struct Digimon {
pub unknown_e2: u8,
}
/// Error type for [`Bytes::from_bytes`]
#[derive(PartialEq, Eq, Clone, Copy, Debug, thiserror::Error)]
pub enum FromBytesError {
/// Unable to read the digimon name
#[error("Unable to read the digimon name")]
Name(#[source] null_ascii_string::ReadError),
/// Unable to read the first support effect description
#[error("Unable to read the first line of the effect description")]
EffectDescription1(#[source] null_ascii_string::ReadError),
/// Unable to read the second support effect description
#[error("Unable to read the second line of the effect description")]
EffectDescription2(#[source] null_ascii_string::ReadError),
/// Unable to read the third support effect description
#[error("Unable to read the third line of the effect description")]
EffectDescription3(#[source] null_ascii_string::ReadError),
/// Unable to read the fourth support effect description
#[error("Unable to read the fourth line of the effect description")]
EffectDescription4(#[source] null_ascii_string::ReadError),
/// An unknown speciality was found
#[error("Unknown speciality found")]
Speciality(#[source] property::speciality::FromBytesError),
/// An unknown level was found
#[error("Unknown level found")]
Level(#[source] property::level::FromBytesError),
/// An unknown effect arrow color was found
#[error("Unknown effect arrow color found")]
ArrowColor(#[source] property::arrow_color::FromBytesError),
/// An unknown cross move effect was found
#[error("Unknown cross move effect found")]
CrossMoveEffect(#[source] property::cross_move_effect::FromBytesError),
/// Unable to read the circle move
#[error("Unable to read the circle move")]
MoveCircle(#[source] property::moves::FromBytesError),
/// Unable to read the triangle move
#[error("Unable to read the triangle move")]
MoveTriangle(#[source] property::moves::FromBytesError),
/// Unable to read the cross move
#[error("Unable to read the cross move")]
MoveCross(#[source] property::moves::FromBytesError),
/// Unable to read the first effect condition
#[error("Unable to read the first effect condition")]
EffectConditionFirst(#[source] property::effect_condition::FromBytesError),
/// Unable to read the second effect condition
#[error("Unable to read the second effect condition")]
EffectConditionSecond(#[source] property::effect_condition::FromBytesError),
/// Unable to read the first effect
#[error("Unable to read the first effect")]
EffectFirst(#[source] property::effect::FromBytesError),
/// Unable to read the second effect
#[error("Unable to read the second effect")]
EffectSecond(#[source] property::effect::FromBytesError),
/// Unable to read the third effect
#[error("Unable to read the third effect")]
EffectThird(#[source] property::effect::FromBytesError),
}
/// Error type for [`Bytes::to_bytes`]
#[derive(PartialEq, Eq, Clone, Copy, Debug, thiserror::Error)]
#[allow(clippy::pub_enum_variant_names)] // This is a general error, not a specific effect error
pub enum ToBytesError {
/// Unable to write the first effect
#[error("Unable to write the first effect")]
EffectFirst(#[source] property::effect::ToBytesError),
/// Unable to write the second effect
#[error("Unable to write the second effect")]
EffectSecond(#[source] property::effect::ToBytesError),
/// Unable to write the third effect
#[error("Unable to write the third effect")]
EffectThird(#[source] property::effect::ToBytesError),
}
impl Bytes for Digimon {
type ByteArray = [u8; 0x138];
type FromError = FromBytesError;

View File

@@ -0,0 +1,93 @@
//! Errors
// Imports
use crate::{game::card::property, util::null_ascii_string};
/// Error type for [`Bytes::from_bytes`]
#[derive(PartialEq, Eq, Clone, Copy, Debug, thiserror::Error)]
pub enum FromBytesError {
/// Unable to read the digimon name
#[error("Unable to read the digimon name")]
Name(#[source] null_ascii_string::ReadError),
/// Unable to read the first support effect description
#[error("Unable to read the first line of the effect description")]
EffectDescription1(#[source] null_ascii_string::ReadError),
/// Unable to read the second support effect description
#[error("Unable to read the second line of the effect description")]
EffectDescription2(#[source] null_ascii_string::ReadError),
/// Unable to read the third support effect description
#[error("Unable to read the third line of the effect description")]
EffectDescription3(#[source] null_ascii_string::ReadError),
/// Unable to read the fourth support effect description
#[error("Unable to read the fourth line of the effect description")]
EffectDescription4(#[source] null_ascii_string::ReadError),
/// An unknown speciality was found
#[error("Unknown speciality found")]
Speciality(#[source] property::speciality::FromBytesError),
/// An unknown level was found
#[error("Unknown level found")]
Level(#[source] property::level::FromBytesError),
/// An unknown effect arrow color was found
#[error("Unknown effect arrow color found")]
ArrowColor(#[source] property::arrow_color::FromBytesError),
/// An unknown cross move effect was found
#[error("Unknown cross move effect found")]
CrossMoveEffect(#[source] property::cross_move_effect::FromBytesError),
/// Unable to read the circle move
#[error("Unable to read the circle move")]
MoveCircle(#[source] property::moves::FromBytesError),
/// Unable to read the triangle move
#[error("Unable to read the triangle move")]
MoveTriangle(#[source] property::moves::FromBytesError),
/// Unable to read the cross move
#[error("Unable to read the cross move")]
MoveCross(#[source] property::moves::FromBytesError),
/// Unable to read the first effect condition
#[error("Unable to read the first effect condition")]
EffectConditionFirst(#[source] property::effect_condition::FromBytesError),
/// Unable to read the second effect condition
#[error("Unable to read the second effect condition")]
EffectConditionSecond(#[source] property::effect_condition::FromBytesError),
/// Unable to read the first effect
#[error("Unable to read the first effect")]
EffectFirst(#[source] property::effect::FromBytesError),
/// Unable to read the second effect
#[error("Unable to read the second effect")]
EffectSecond(#[source] property::effect::FromBytesError),
/// Unable to read the third effect
#[error("Unable to read the third effect")]
EffectThird(#[source] property::effect::FromBytesError),
}
/// Error type for [`Bytes::to_bytes`]
#[derive(PartialEq, Eq, Clone, Copy, Debug, thiserror::Error)]
#[allow(clippy::pub_enum_variant_names)] // This is a general error, not a specific effect error
pub enum ToBytesError {
/// Unable to write the first effect
#[error("Unable to write the first effect")]
EffectFirst(#[source] property::effect::ToBytesError),
/// Unable to write the second effect
#[error("Unable to write the second effect")]
EffectSecond(#[source] property::effect::ToBytesError),
/// Unable to write the third effect
#[error("Unable to write the third effect")]
EffectThird(#[source] property::effect::ToBytesError),
}