1use crate::panic_builder;
2
3pub mod alloc;
4pub use alloc::*;
5
6pub mod refer;
7pub use refer::*;
8
9#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
14pub enum CreateMessageError {
15 #[error("Invalid argument number: {number} is out of the allowed range (0 <= number < {n}).")]
20 InvalidNumber { number: usize, n: usize },
21
22 #[error("Missing argument number: {number} is not found within the allowed range (0 <= number < {n}).")]
27 WithoutNumber { number: usize, n: usize },
28 #[error("Empty placeholder found: a placeholder was opened but not closed properly. Ensure all placeholders are correctly formatted.")]
33 EmptyPlaceholder,
34}
35
36impl CreateMessageError {
37 #[track_caller]
38 pub const fn panic(&self) -> ! {
39 match self {
40 Self::InvalidNumber { number, n } => {
41 const MESSAGE: StaticMessage<2> = local_fmt::StaticMessage::new_panic(&[
42 local_fmt::RefMessageFormat::RefText("Invalid argument number: "),
43 local_fmt::RefMessageFormat::Placeholder(0usize),
44 local_fmt::RefMessageFormat::RefText(
45 " is out of the allowed range (0 <= number < ",
46 ),
47 local_fmt::RefMessageFormat::Placeholder(1usize),
48 local_fmt::RefMessageFormat::RefText(")."),
49 ]);
50 panic_builder!(MESSAGE, [u; *number], [u; *n])
51 }
52 Self::WithoutNumber { number, n } => {
53 const MESSAGE: StaticMessage<2> = local_fmt::StaticMessage::<2usize>::new_panic(&[
54 local_fmt::RefMessageFormat::RefText("Missing argument number: "),
55 local_fmt::RefMessageFormat::Placeholder(0usize),
56 local_fmt::RefMessageFormat::RefText(
57 " is not found within the allowed range (0 <= number < ",
58 ),
59 local_fmt::RefMessageFormat::Placeholder(1usize),
60 local_fmt::RefMessageFormat::RefText(")."),
61 ]);
62
63 panic_builder!(MESSAGE, [u; *number], [u; *n])
64 }
65 Self::EmptyPlaceholder => {
66 panic!("Empty placeholder found: a placeholder was opened but not closed properly. Ensure all placeholders are correctly formatted.")
67 }
68 }
69 }
70}