aboutsummaryrefslogtreecommitdiff
path: root/src/passwordmaker/base_conversion/mod.rs
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2022-10-23 15:09:23 +0200
committerAndreas Grois <andi@grois.info>2022-10-23 15:09:23 +0200
commitd5b30baf4dd8ff8dbc4c0bd22b9178c914cbe973 (patch)
treefab24ca33da16ffd2b0517aeea34cd913cff2683 /src/passwordmaker/base_conversion/mod.rs
parentf9938b7e5afedf5bd09095210c4a640b10c72687 (diff)
Precompute power+exponent for iterative conversion
The maximum power of the base that can fit into a given data type is constant. There's no point in computing it at runtime, if we can just store it in a compile-time constants array. The code isn't the most beautiful, but that's mostly because Rust const functions are still a bit limited. One function was duplicated, because it was easy to get a slow version to compile in const context, and const context doesn't really care...
Diffstat (limited to 'src/passwordmaker/base_conversion/mod.rs')
-rw-r--r--src/passwordmaker/base_conversion/mod.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/passwordmaker/base_conversion/mod.rs b/src/passwordmaker/base_conversion/mod.rs
index dc98c92..bb3fbd6 100644
--- a/src/passwordmaker/base_conversion/mod.rs
+++ b/src/passwordmaker/base_conversion/mod.rs
@@ -3,6 +3,8 @@ use iterative_conversion_impl::PadWithAZero;
pub(super) use iterative_conversion::IterativeBaseConversion;
pub(super) use iterative_conversion_impl::{SixteenBytes, ArbitraryBytes};
+use self::iterative_conversion::ConstantMaxPotencyCache;
+
mod iterative_conversion;
mod iterative_conversion_impl;
@@ -14,7 +16,7 @@ pub(super) trait BaseConversion {
impl<T, const N : usize, const M : usize> BaseConversion for T
where T : ToArbitraryBytes<Output = ArbitraryBytes<N>>,
- for<'a> T::Output: From<&'a usize> + From<&'a u32> + PadWithAZero<Output = ArbitraryBytes<M>>,
+ for<'a> T::Output: From<&'a usize> + From<&'a u32> + PadWithAZero<Output = ArbitraryBytes<M>> + ConstantMaxPotencyCache<usize>,
{
type Output = IterativeBaseConversion<ArbitraryBytes<N>, usize>;
fn convert_to_base(self, base : usize) -> Self::Output {