1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
//! Miscelaneous utility functions.
use const_panic::PanicVal;
/// Constructs an array by repeating `repeated`. Most useful when `LENGTH` can be inferred.
///
/// # Example
///
/// ```rust
/// use const_base::utils::repeated;
///
/// const ARR: [u8; 4] = repeated(5);
///
/// assert_eq!(ARR, [5, 5, 5, 5]);
/// ```
#[inline(always)]
pub const fn repeated<const LENGTH: usize>(repeated: u8) -> [u8; LENGTH] {
[repeated; LENGTH]
}
#[cold]
#[track_caller]
#[inline(never)]
pub(crate) const fn cpanic(pvs: &[PanicVal<'_>]) -> ! {
const_panic::concat_panic(&[
&[PanicVal::write_str("\n\n")],
pvs,
&[PanicVal::write_str("\n\n")],
])
}