const_panic/utils/
non_basic_utils.rs1use crate::{FmtArg, PanicVal};
2
3pub const fn panicvals_id<'a, 'b, const LEN: usize>(
5 array: &'b [PanicVal<'a>; LEN],
6) -> &'b [PanicVal<'a>] {
7 array
8}
9
10pub const fn flatten_panicvals<'a, const LEN: usize>(
20 mut input: &[&[PanicVal<'a>]],
21) -> [PanicVal<'a>; LEN] {
22 let mut out = [PanicVal::EMPTY; LEN];
23 let mut len = 0usize;
24
25 while let [mut outer, ref rinput @ ..] = *input {
26 while let [arg, ref router @ ..] = *outer {
27 out[len] = arg;
28 len += 1;
29 outer = router;
30 }
31 input = rinput
32 }
33
34 out
35}
36
37pub const fn max_usize(l: usize, r: usize) -> usize {
49 if l > r {
50 l
51 } else {
52 r
53 }
54}
55
56pub const fn slice_max_usize(mut slice: &[usize]) -> usize {
71 let mut max = 0;
72
73 while let [x, ref rem @ ..] = *slice {
74 max = max_usize(max, x);
75 slice = rem;
76 }
77
78 max
79}
80
81#[doc(hidden)]
82#[track_caller]
83pub const fn assert_flatten_panicvals_length(expected_larger: usize, actual_value: usize) {
84 if actual_value > expected_larger {
85 crate::concat_panic(&[&[
86 PanicVal::write_str("length passed to flatten_panicvals macro ("),
87 PanicVal::from_usize(expected_larger, FmtArg::DISPLAY),
88 PanicVal::write_str(") is smaller than the computed length ("),
89 PanicVal::from_usize(actual_value, FmtArg::DISPLAY),
90 PanicVal::write_str(")"),
91 ]]);
92 }
93}