1#![doc(hidden)]
4
5#[cfg(any(feature = "write-floats", feature = "write-integers"))]
6use crate::constants::FormattedSize;
7
8#[inline(always)]
12#[cfg(feature = "radix")]
13pub fn debug_assert_radix(radix: u32) {
14 debug_assert!((2..=36).contains(&radix), "Numerical base must be from 2-36.");
15}
16
17#[inline(always)]
19#[cfg(all(feature = "power-of-two", not(feature = "radix")))]
20pub fn debug_assert_radix(radix: u32) {
21 debug_assert!(matches!(radix, 2 | 4 | 8 | 10 | 16 | 32), "Numerical base must be from 2-36.");
22}
23
24#[inline(always)]
26#[cfg(not(feature = "power-of-two"))]
27pub fn debug_assert_radix(radix: u32) {
28 debug_assert!(radix == 10, "Numerical base must be 10.");
29}
30
31#[inline(always)]
35#[cfg(all(feature = "power-of-two", any(feature = "write-floats", feature = "write-integers")))]
36pub const fn assert_buffer<T: FormattedSize>(radix: u32, len: usize) {
37 assert!(
38 match radix {
39 10 => len >= T::FORMATTED_SIZE_DECIMAL,
40 _ => len >= T::FORMATTED_SIZE,
41 },
42 "Buffer is too small: may overwrite buffer, panicking!"
43 );
44}
45
46#[inline(always)]
48#[cfg(all(
49 not(feature = "power-of-two"),
50 any(feature = "write-floats", feature = "write-integers")
51))]
52pub const fn assert_buffer<T: FormattedSize>(_: u32, len: usize) {
53 assert!(
54 len >= T::FORMATTED_SIZE_DECIMAL,
55 "Buffer is too small: may overwrite buffer, panicking!"
56 );
57}