From 4cccbfdf7628442cc198f6399846ad4e98938494 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 Dec 2024 12:54:55 +1100 Subject: [PATCH] units: Seal the Integer trait This trait is an internal thing, users should never implement it. --- units/src/parse.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/units/src/parse.rs b/units/src/parse.rs index a08fd5692..923ae9c76 100644 --- a/units/src/parse.rs +++ b/units/src/parse.rs @@ -52,18 +52,24 @@ impl AsRef 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 + TryFrom + Sized {} +pub trait Integer: FromStr + TryFrom + 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` which is not used later it's better to pass it as