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