1pub(crate) trait MaybeSplitAt<T> {
6 fn debug_split_at(&self, mid: usize) -> (&Self, &Self);
9}
10
11impl<T> MaybeSplitAt<T> for [T] {
12 #[inline]
13 fn debug_split_at(&self, mid: usize) -> (&Self, &Self) {
14 self.split_at_checked(mid).unwrap_or_else(|| {
15 if true {
if !false {
{
::core::panicking::panic_fmt(format_args!("debug_split_at: {0} expected to be in range",
mid));
}
};
};debug_assert!(false, "debug_split_at: {mid} expected to be in range");
16 (self, &[])
17 })
18 }
19}
20
21pub(crate) trait DebugUnwrapOr<T> {
22 fn debug_unwrap_or(self, gigo_value: T) -> T;
24}
25
26impl<T> DebugUnwrapOr<T> for Option<T> {
27 #[inline]
28 fn debug_unwrap_or(self, gigo_value: T) -> T {
29 match self {
30 Some(x) => x,
31 None => {
32 if true {
if !false {
{
::core::panicking::panic_fmt(format_args!("debug_unwrap_or called on a None value"));
}
};
};debug_assert!(false, "debug_unwrap_or called on a None value");
33 gigo_value
34 }
35 }
36 }
37}
38
39macro_rules! debug_unwrap {
40 ($expr:expr, return $retval:expr, $($arg:tt)+) => {
41 match $expr {
42 Some(x) => x,
43 None => {
44 debug_assert!(false, $($arg)*);
45 return $retval;
46 }
47 }
48 };
49 ($expr:expr, return $retval:expr) => {
50 debug_unwrap!($expr, return $retval, "invalid trie")
51 };
52 ($expr:expr, break, $($arg:tt)+) => {
53 match $expr {
54 Some(x) => x,
55 None => {
56 debug_assert!(false, $($arg)*);
57 break;
58 }
59 }
60 };
61}
62
63pub(crate) use debug_unwrap;
64
65pub(crate) const MAX_USIZE_LEN_AS_DIGITS: usize = size_of::<usize>() * 24 / 10 + 1;
68
69#[allow(clippy::indexing_slicing)] pub(crate) const fn const_fmt_int<const M: usize, const N: usize>(
78 prefix: [u8; M],
79 value: usize,
80) -> [u8; N] {
81 let mut output = [b' '; N];
82 let mut i = 0;
83 while i < M {
84 output[i] = prefix[i];
85 i += 1;
86 }
87 let mut int_only = [b' '; MAX_USIZE_LEN_AS_DIGITS];
88 let mut value = value;
89 let mut i = MAX_USIZE_LEN_AS_DIGITS - 1;
90 loop {
91 let x = (value % 10) as u8;
92 int_only[i] = x + b'0';
93 value /= 10;
94 if value == 0 {
95 break;
96 }
97 i -= 1;
98 }
99 let mut j = M;
100 while i < MAX_USIZE_LEN_AS_DIGITS {
101 output[j] = int_only[i];
102 j += 1;
103 i += 1;
104 }
105 output
106}
107
108#[test]
109fn test_const_fmt_int() {
110 assert_eq!(*b"123", const_fmt_int::<0, 3>(*b"", 123));
111 assert_eq!(*b"123 ", const_fmt_int::<0, 6>(*b"", 123));
112 assert_eq!(*b"abc123", const_fmt_int::<3, 6>(*b"abc", 123));
113}