1//! Debugging assertions to check a radix is valid.
23#[cfg(feature = "write")]
4use crate::constants::FormattedSize;
56// RADIX
78/// Check radix is in range `[2, 36]` in debug builds.
9#[inline(always)]
10#[cfg(feature = "radix")]
11pub fn debug_assert_radix(radix: u32) {
12debug_assert!((2..=36).contains(&radix), "Numerical base must be from 2-36.");
13}
1415/// Check radix is is 10 or a power of 2.
16#[inline(always)]
17#[cfg(all(feature = "power-of-two", not(feature = "radix")))]
18pub fn debug_assert_radix(radix: u32) {
19debug_assert!(matches!(radix, 2 | 4 | 8 | 10 | 16 | 32), "Numerical base must be from 2-36.");
20}
2122/// Check radix is equal to 10.
23#[inline(always)]
24#[cfg(not(feature = "power-of-two"))]
25pub fn debug_assert_radix(radix: u32) {
26debug_assert!(radix == 10, "Numerical base must be 10.");
27}
2829// BUFFER
3031/// Assertion the buffer has sufficient room for the output.
32#[inline(always)]
33#[cfg(all(feature = "power-of-two", feature = "write"))]
34pub fn assert_buffer<T: FormattedSize>(radix: u32, len: usize) {
35assert!(
36match radix {
3710 => len >= T::FORMATTED_SIZE_DECIMAL,
38_ => len >= T::FORMATTED_SIZE,
39 },
40"Buffer is too small: may overwrite buffer, panicking!"
41);
42}
4344/// Assertion the buffer has sufficient room for the output.
45#[inline(always)]
46#[cfg(all(not(feature = "power-of-two"), feature = "write"))]
47pub fn assert_buffer<T: FormattedSize>(_: u32, len: usize) {
48assert!(
49 len >= T::FORMATTED_SIZE_DECIMAL,
50"Buffer is too small: may overwrite buffer, panicking!"
51);
52}