const_panic/fmt_impls/
rust_1_64_fmt_impls.rs1use crate::{
2 fmt::{FmtArg, FmtKind, PanicFmt},
3 PanicVal, StdWrapper,
4};
5
6use core::str::Utf8Error;
7
8#[cfg_attr(feature = "docsrs", doc(cfg(feature = "rust_1_64")))]
9impl PanicFmt for Utf8Error {
10 type This = Self;
11 type Kind = crate::fmt::IsStdType;
12 const PV_COUNT: usize = 5;
13}
14
15#[cfg_attr(feature = "docsrs", doc(cfg(feature = "rust_1_64")))]
16impl StdWrapper<&Utf8Error> {
17 pub const fn to_panicvals(self, fmtarg: FmtArg) -> [PanicVal<'static>; Utf8Error::PV_COUNT] {
19 let this = *self.0;
20 match fmtarg.fmt_kind {
21 FmtKind::Display => {
22 let [pv0, pv1, pv2] = match this.error_len() {
23 Some(x) => [
24 PanicVal::write_str("invalid utf-8 sequence of "),
25 PanicVal::from_usize(x, fmtarg),
26 PanicVal::write_str(" bytes "),
27 ],
28 None => [
29 PanicVal::write_str("incomplete utf-8 byte sequence "),
30 PanicVal::EMPTY,
31 PanicVal::EMPTY,
32 ],
33 };
34
35 [
36 pv0,
37 pv1,
38 pv2,
39 PanicVal::write_str("from index "),
40 PanicVal::from_usize(this.valid_up_to(), fmtarg),
41 ]
42 }
43 FmtKind::Debug => {
44 let [pv0, pv1, pv2] = match this.error_len() {
45 Some(x) => [
46 PanicVal::write_str(", error_len: Some("),
47 PanicVal::from_usize(x, fmtarg),
48 PanicVal::write_str(") }"),
49 ],
50 None => [
51 PanicVal::write_str(", error_len: None }"),
52 PanicVal::EMPTY,
53 PanicVal::EMPTY,
54 ],
55 };
56
57 [
58 PanicVal::write_str("Utf8Error { valid_up_to: "),
59 PanicVal::from_usize(this.valid_up_to(), fmtarg),
60 pv0,
61 pv1,
62 pv2,
63 ]
64 }
65 }
66 }
67}