From e044797c0667722285204560b08be2a72d422573 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Tue, 16 Jan 2024 11:22:54 -0700 Subject: [PATCH] Make `Uint::split` const generic over inputs This allows a `const fn` to be written which is bounded on the `Split` trait, and generic over a number of input limbs. --- src/uint/macros.rs | 7 ------- src/uint/split.rs | 10 +++++++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/uint/macros.rs b/src/uint/macros.rs index b43ef1a2e..689482f8b 100644 --- a/src/uint/macros.rs +++ b/src/uint/macros.rs @@ -136,13 +136,6 @@ macro_rules! impl_uint_concat_split_even { { type Output = Uint<{ <$name>::LIMBS / 2 }>; } - - impl $name { - /// Split this number in half, returning its low and high components respectively. - pub const fn split(&self) -> (Uint<{ <$name>::LIMBS / 2 }>, Uint<{ <$name>::LIMBS / 2 }>) { - self.split_mixed() - } - } }; ($($name:ident,)+) => { $( diff --git a/src/uint/split.rs b/src/uint/split.rs index e93cb39f5..9421c9fae 100644 --- a/src/uint/split.rs +++ b/src/uint/split.rs @@ -1,6 +1,14 @@ -use crate::{Limb, SplitMixed, Uint}; +use crate::{Limb, Split, SplitMixed, Uint}; impl Uint { + /// Split this number in half into low and high components. + pub const fn split(&self) -> (Uint, Uint) + where + Self: Split>, + { + self.split_mixed() + } + /// Split this number into low and high components respectively. #[inline] pub const fn split_mixed(&self) -> (Uint, Uint)