num_primitive/error.rs
1use core::error::Error;
2
3trait Sealed {}
4
5/// Trait for errors that may be returned in numeric conversions.
6///
7/// In particular, this is used as a bound for the associated error types of
8/// [`FromStr`][core::str::FromStr], [`TryFrom`], and [`TryInto`] in the supertraits of other
9/// primitive traits in this crate. This is not exhaustive of everything these errors have in
10/// common, but it's sufficient for:
11///
12/// * `Result::clone()`
13/// * `Result::eq()` (i.e. `PartialEq`)
14/// * `Result::unwrap()` (i.e. `Debug`)
15/// * `From<E> for Box<dyn Error + 'a>`
16/// * `From<E> for Box<dyn Error + Send + Sync + 'a>`
17///
18/// This trait is sealed with a private trait to prevent downstream implementations, so we may
19/// continue to expand along with the standard library without worrying about breaking changes for
20/// implementors.
21#[expect(private_bounds)]
22pub trait PrimitiveError: 'static + Sealed + Clone + PartialEq + Error + Send + Sync {}
23
24impl Sealed for core::convert::Infallible {}
25impl PrimitiveError for core::convert::Infallible {}
26
27impl Sealed for core::num::ParseIntError {}
28impl PrimitiveError for core::num::ParseIntError {}
29
30impl Sealed for core::num::ParseFloatError {}
31impl PrimitiveError for core::num::ParseFloatError {}
32
33impl Sealed for core::num::TryFromIntError {}
34impl PrimitiveError for core::num::TryFromIntError {}