pub(crate) trait MaybeSplitAt<T> { /// Like slice::split_at but debug-panics and returns an empty second slice /// if the index is out of range. fn debug_split_at(&self, mid: usize) -> (&Self, &Self);
}
impl<T> MaybeSplitAt<T> for [T] { #[inline] fn debug_split_at(&self, mid: usize) -> (&Self, &Self) { self.split_at_checked(mid).unwrap_or_else(|| {
debug_assert!(false, "debug_split_at: {mid} expected to be in range");
(self, &[])
})
}
}
pub(crate) trait DebugUnwrapOr<T> { /// Unwraps the option or panics in debug mode, returning the `gigo_value` fn debug_unwrap_or(self, gigo_value: T) -> T;
}
impl<T> DebugUnwrapOr<T> for Option<T> { #[inline] fn debug_unwrap_or(self, gigo_value: T) -> T { matchself {
Some(x) => x,
None => {
debug_assert!(false, "debug_unwrap_or called on a None value");
gigo_value
}
}
}
}
/// The maximum number of base-10 digits required for rendering a usize. /// Note: 24/10 is an approximation of 8*log10(2) pub(crate) const MAX_USIZE_LEN_AS_DIGITS: usize = core::mem::size_of::<usize>() * 24 / 10 + 1;
/// Formats a usize as a string of length N, padded with spaces, /// with the given prefix. /// /// If the string is too short, the function may panic. To prevent /// this, N should be MAX_USIZE_LEN_AS_DIGITS larger than M. pub(crate) constfn const_fmt_int<const M: usize, const N: usize>(
prefix: [u8; M],
value: usize,
) -> [u8; N] { letmut output = [b' '; N]; letmut i = 0; while i < M {
output[i] = prefix[i];
i += 1;
} letmut int_only = [b' '; MAX_USIZE_LEN_AS_DIGITS]; letmut value = value; letmut i = MAX_USIZE_LEN_AS_DIGITS - 1; loop { let x = (value % 10) as u8;
int_only[i] = x + b'0';
value /= 10; if value == 0 { break;
}
i -= 1;
} letmut j = M; while i < MAX_USIZE_LEN_AS_DIGITS {
output[j] = int_only[i];
j += 1;
i += 1;
}
output
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.