Merge rust-bitcoin/rust-bitcoin#3724: units: Seal the `Integer` trait

4cccbfdf76 units: Seal the Integer trait (Tobin C. Harding)

Pull request description:

  This trait is an internal thing, users should never implement it.

ACKs for top commit:
  sanket1729:
    utACK 4cccbfdf76
  apoelstra:
    ACK 4cccbfdf7628442cc198f6399846ad4e98938494; successfully ran local tests

Tree-SHA512: f48e8ef96d15135990976c77e933ddc735dda577464548478526e37fff49bf453aaacf966967d98a0d5598588b531199627af8e353f845d4c7781f1e1d8de6db
This commit is contained in:
merge-script 2024-12-14 14:33:27 +00:00
commit 834010d681
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
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