move warning and errors now implement std::error::Error.

`From` / `Into` implementations for `Data` and `u64` are now done using `derive_more`.
This commit is contained in:
2020-09-11 13:28:49 +01:00
parent 2ec0a90e58
commit e85527fdbf
2 changed files with 5 additions and 18 deletions

View File

@@ -111,19 +111,17 @@ impl Validatable for Move {
}
/// All warnings for [`Move`] validation
#[derive(PartialEq, Eq, Clone, Debug)]
#[derive(derive_more::Display)]
#[derive(PartialEq, Eq, Clone, Debug, thiserror::Error)]
pub enum ValidationWarning {
/// Power is not a multiple of 10
#[display(fmt = "Power is not a multiple of 10.")]
#[error("Power is not a multiple of 10.")]
PowerMultiple10,
}
/// All errors for [`Move`] validation
#[derive(PartialEq, Eq, Clone, Debug)]
#[derive(derive_more::Display)]
#[derive(PartialEq, Eq, Clone, Debug, thiserror::Error)]
pub enum ValidationError {
/// Name length
#[display(fmt = "Name is too long. Must be at most 21 characters")]
#[error("Name is too long. Must be at most 21 characters")]
NameTooLong,
}

View File

@@ -14,6 +14,7 @@ use crate::{
/// All addresses of type `Data` will represent the position
/// within *only* the data sections on the file.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(derive_more::From, derive_more::Into)]
pub struct Data(u64);
impl Data {
@@ -68,18 +69,6 @@ impl Data {
}
}
// Conversions from and into u64
impl From<Data> for u64 {
fn from(address: Data) -> Self {
address.0
}
}
impl From<u64> for Data {
fn from(address: u64) -> Self {
Self(address)
}
}
// Data + Offset
impl std::ops::Add<i64> for Data {
type Output = Self;