From 389347e04e430e406af3d80880f28830a1b10d17 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 8 Feb 2024 19:33:01 -0500 Subject: [PATCH] and a few more --- lib/oxsdatatypes/src/date_time.rs | 13 +++---------- lib/oxsdatatypes/src/decimal.rs | 12 ++---------- lib/oxsdatatypes/src/integer.rs | 12 ++---------- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/lib/oxsdatatypes/src/date_time.rs b/lib/oxsdatatypes/src/date_time.rs index 0f50f5dc..1acb2197 100644 --- a/lib/oxsdatatypes/src/date_time.rs +++ b/lib/oxsdatatypes/src/date_time.rs @@ -2,7 +2,6 @@ use crate::{DayTimeDuration, Decimal, Duration, YearMonthDuration}; use std::cmp::{min, Ordering}; -use std::error::Error; use std::fmt; use std::hash::{Hash, Hasher}; use std::str::FromStr; @@ -2387,17 +2386,10 @@ fn validate_day_of_month(year: Option, month: u8, day: u8) -> Result<(), Pa /// An overflow during [`DateTime`]-related operations. /// /// Matches XPath [`FODT0001` error](https://www.w3.org/TR/xpath-functions-31/#ERRFODT0001). -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, thiserror::Error)] +#[error("overflow during xsd:dateTime computation")] pub struct DateTimeOverflowError; -impl fmt::Display for DateTimeOverflowError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("overflow during xsd:dateTime computation") - } -} - -impl Error for DateTimeOverflowError {} - /// The value provided as timezone is not valid. /// /// Matches XPath [`FODT0003` error](https://www.w3.org/TR/xpath-functions-31/#ERRFODT0003). @@ -2414,6 +2406,7 @@ mod tests { #![allow(clippy::panic_in_result_fn)] use super::*; + use std::error::Error; #[test] fn from_str() -> Result<(), ParseDateTimeError> { diff --git a/lib/oxsdatatypes/src/decimal.rs b/lib/oxsdatatypes/src/decimal.rs index 8005800d..ecb01af8 100644 --- a/lib/oxsdatatypes/src/decimal.rs +++ b/lib/oxsdatatypes/src/decimal.rs @@ -1,5 +1,4 @@ use crate::{Boolean, Double, Float, Integer, TooLargeForIntegerError}; -use std::error::Error; use std::fmt; use std::fmt::Write; use std::str::FromStr; @@ -630,17 +629,10 @@ impl From for ParseDecimalError { /// The input is too large to fit into a [`Decimal`]. /// /// Matches XPath [`FOCA0001` error](https://www.w3.org/TR/xpath-functions-31/#ERRFOCA0001). -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, thiserror::Error)] +#[error("Value too large for xsd:decimal internal representation")] pub struct TooLargeForDecimalError; -impl fmt::Display for TooLargeForDecimalError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("Value too large for xsd:decimal internal representation") - } -} - -impl Error for TooLargeForDecimalError {} - #[cfg(test)] mod tests { #![allow(clippy::panic_in_result_fn)] diff --git a/lib/oxsdatatypes/src/integer.rs b/lib/oxsdatatypes/src/integer.rs index b28638d2..d0a693ea 100644 --- a/lib/oxsdatatypes/src/integer.rs +++ b/lib/oxsdatatypes/src/integer.rs @@ -1,5 +1,4 @@ use crate::{Boolean, Decimal, Double, Float}; -use std::error::Error; use std::fmt; use std::num::ParseIntError; use std::str::FromStr; @@ -264,17 +263,10 @@ impl TryFrom for Integer { /// The input is too large to fit into an [`Integer`]. /// /// Matches XPath [`FOCA0003` error](https://www.w3.org/TR/xpath-functions-31/#ERRFOCA0003). -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, thiserror::Error)] +#[error("Value too large for xsd:integer internal representation")] pub struct TooLargeForIntegerError; -impl fmt::Display for TooLargeForIntegerError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("Value too large for xsd:integer internal representation") - } -} - -impl Error for TooLargeForIntegerError {} - #[cfg(test)] mod tests { #![allow(clippy::panic_in_result_fn)]