use crate::{DecimalType, PrimitiveType, Type};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ParseCalendarError {
InvalidLexical,
OutOfRange,
UnsupportedTimezone,
}
impl core::fmt::Display for ParseCalendarError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(match self {
Self::InvalidLexical => "invalid XSD partial-calendar lexical form",
Self::OutOfRange => "XSD partial-calendar fields are outside the supported range",
Self::UnsupportedTimezone => {
"timezone-bearing XSD partial-calendar values are not yet supported"
},
})
}
}
impl core::error::Error for ParseCalendarError {}
pub type ParseBooleanError = ParseError;
pub type ParseDoubleError = ParseFloatError;
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ParseFloatError {
InvalidLexical,
Backend(
core::num::ParseFloatError,
),
}
impl core::fmt::Display for ParseFloatError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidLexical => f.write_str("invalid XSD floating-point lexical form"),
Self::Backend(source) => source.fmt(f),
}
}
}
impl core::error::Error for ParseFloatError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::InvalidLexical => None,
Self::Backend(source) => Some(source),
}
}
}
impl From<core::num::ParseFloatError> for ParseFloatError {
fn from(source: core::num::ParseFloatError) -> Self {
Self::Backend(source)
}
}
pub type ParseIntegerError = core::num::ParseIntError;
#[cfg(feature = "jiff")]
pub type ParseDateTimeError = jiff::Error;
#[cfg(feature = "jiff")]
pub type ParseDurationError = jiff::Error;
#[cfg(feature = "jiff")]
#[derive(Debug)]
pub struct ParseTemporalError(
pub jiff::Error,
);
#[cfg(feature = "jiff")]
impl core::fmt::Display for ParseTemporalError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
#[cfg(feature = "jiff")]
impl core::error::Error for ParseTemporalError {}
#[derive(Debug)]
#[non_exhaustive]
pub enum ParseError {
InvalidCalendar {
datatype: PrimitiveType,
source: ParseCalendarError,
},
InvalidLiteral,
InvalidBoolean,
InvalidInteger {
datatype: DecimalType,
source: ParseIntegerError,
},
InvalidDecimal {
datatype: Type,
source: ParseDecimalError,
},
InvalidFloat {
datatype: PrimitiveType,
source: ParseFloatError,
},
#[cfg(feature = "jiff")]
InvalidTemporal {
datatype: PrimitiveType,
source: ParseTemporalError,
},
UnsupportedDatatype(Type),
}
impl core::fmt::Display for ParseError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Self::InvalidCalendar { datatype, source } => {
write!(f, "invalid {} literal: {source}", datatype.curie())
},
Self::InvalidLiteral => f.write_str("invalid XSD literal"),
Self::InvalidBoolean => {
f.write_str("invalid xsd:boolean literal: expected true, false, 1, or 0")
},
Self::InvalidInteger { datatype, source } => {
write!(f, "invalid {} literal: {source}", datatype.curie())
},
Self::InvalidDecimal { datatype, source } => {
write!(f, "invalid {} literal: {source}", datatype.curie())
},
Self::InvalidFloat { datatype, source } => {
write!(f, "invalid {} literal: {source}", datatype.curie())
},
#[cfg(feature = "jiff")]
Self::InvalidTemporal { datatype, source } => {
write!(f, "invalid {} literal: {source}", datatype.curie())
},
Self::UnsupportedDatatype(datatype) => {
write!(f, "unsupported datatype: {}", datatype.curie())
},
}
}
}
impl core::error::Error for ParseError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::InvalidCalendar { source, .. } => Some(source),
Self::InvalidInteger { source, .. } => Some(source),
Self::InvalidDecimal { source, .. } => Some(source),
Self::InvalidFloat { source, .. } => Some(source),
#[cfg(feature = "jiff")]
Self::InvalidTemporal { source, .. } => Some(source),
_ => None,
}
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum ParseDecimalError {
InvalidLexical,
Backend(
valuand::DecimalError,
),
}
impl core::fmt::Display for ParseDecimalError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidLexical => f.write_str("invalid XSD decimal lexical form"),
Self::Backend(source) => source.fmt(f),
}
}
}
impl core::error::Error for ParseDecimalError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::InvalidLexical => None,
Self::Backend(source) => Some(source),
}
}
}
impl From<valuand::DecimalError> for ParseDecimalError {
fn from(source: valuand::DecimalError) -> Self {
Self::Backend(source)
}
}