units: Seal the Integer trait

This trait is an internal thing, users should never implement it.
This commit is contained in:
Tobin C. Harding 2024-12-11 12:54:55 +11:00
parent aeca93b561
commit 4cccbfdf76
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 7 additions and 1 deletions

View File

@ -52,18 +52,24 @@ impl AsRef<core::num::ParseIntError> for ParseIntError {
/// Not strictly necessary but serves as a lint - avoids weird behavior if someone accidentally
/// passes non-integer to the `parse()` function.
pub trait Integer: FromStr<Err = core::num::ParseIntError> + TryFrom<i8> + Sized {}
pub trait Integer: FromStr<Err = core::num::ParseIntError> + TryFrom<i8> + Sized + sealed::Sealed {}
macro_rules! impl_integer {
($($type:ty),* $(,)?) => {
$(
impl Integer for $type {}
impl sealed::Sealed for $type {}
)*
}
}
impl_integer!(u8, i8, u16, i16, u32, i32, u64, i64, u128, i128);
mod sealed {
/// Seals the extension traits.
pub trait Sealed {}
}
/// Parses the input string as an integer returning an error carrying rich context.
///
/// If the caller owns `String` or `Box<str>` which is not used later it's better to pass it as