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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use crate::{FmtArg, PanicVal};
pub const fn panicvals_id<'a, 'b, const LEN: usize>(
array: &'b [PanicVal<'a>; LEN],
) -> &'b [PanicVal<'a>] {
array
}
pub const fn flatten_panicvals<'a, const LEN: usize>(
mut input: &[&[PanicVal<'a>]],
) -> [PanicVal<'a>; LEN] {
let mut out = [PanicVal::EMPTY; LEN];
let mut len = 0usize;
while let [mut outer, ref rinput @ ..] = *input {
while let [arg, ref router @ ..] = *outer {
out[len] = arg;
len += 1;
outer = router;
}
input = rinput
}
out
}
pub const fn max_usize(l: usize, r: usize) -> usize {
if l > r {
l
} else {
r
}
}
pub const fn slice_max_usize(mut slice: &[usize]) -> usize {
let mut max = 0;
while let [x, ref rem @ ..] = *slice {
max = max_usize(max, x);
slice = rem;
}
max
}
#[doc(hidden)]
#[track_caller]
pub const fn assert_flatten_panicvals_length(expected_larger: usize, actual_value: usize) {
if actual_value > expected_larger {
crate::concat_panic(&[&[
PanicVal::write_str("length passed to flatten_panicvals macro ("),
PanicVal::from_usize(expected_larger, FmtArg::DISPLAY),
PanicVal::write_str(") is smaller than the computed length ("),
PanicVal::from_usize(actual_value, FmtArg::DISPLAY),
PanicVal::write_str(")"),
]]);
}
}