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