use ::core::convert::From;
use ::core::convert::Infallible;
use ::core::error::Error;
use ::core::fmt::Display;
use ::core::fmt::Formatter;
use ::core::fmt::Result;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TryFromCharError(());
impl TryFromCharError {
#[inline]
pub(crate) const fn new() -> Self {
Self(())
}
}
impl Display for TryFromCharError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
f.write_str("unicode code point out of range")
}
}
impl Error for TryFromCharError {}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TryFromIntError(());
impl TryFromIntError {
#[inline]
pub(crate) const fn new() -> Self {
Self(())
}
}
impl Display for TryFromIntError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
f.write_str("out of range integral type conversion attempted")
}
}
impl Error for TryFromIntError {}
const_trait_if! {
#[feature("const_convert")]
impl const From<Infallible> for TryFromIntError {
fn from(other: Infallible) -> Self {
match other {}
}
}
#[feature("const_convert")]
#[cfg(feature = "never_type")]
impl const From<!> for TryFromIntError {
fn from(other: !) -> Self {
match other {}
}
}
}
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
#[non_exhaustive]
pub enum IntErrorKind {
Empty,
InvalidDigit,
PosOverflow,
NegOverflow,
}
#[expect(missing_copy_implementations, reason = "")]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParseIntError {
kind: IntErrorKind,
}
impl ParseIntError {
#[inline]
pub(crate) const fn new(kind: IntErrorKind) -> Self {
Self { kind }
}
#[must_use]
pub const fn kind(&self) -> &IntErrorKind {
&self.kind
}
}
impl Display for ParseIntError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self.kind {
IntErrorKind::Empty => f.write_str("cannot parse integer from empty string"),
IntErrorKind::InvalidDigit => f.write_str("invalid digit found in string"),
IntErrorKind::PosOverflow => f.write_str("number too large to fit in target type"),
IntErrorKind::NegOverflow => f.write_str("number too small to fit in target type"),
}
}
}
impl Error for ParseIntError {}