datalog_structural_model/error_code.rs
1//! [`ErrorCode`] — stable, kebab-case identifiers for error variants.
2
3use std::fmt;
4
5/// Stable machine-readable identifier of an error variant.
6///
7/// Codes are kebab-case and never change when a variant is renamed; the
8/// census test pins every one.
9#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10pub struct ErrorCode(&'static str);
11
12impl ErrorCode {
13 pub(crate) const fn new(code: &'static str) -> Self {
14 Self(code)
15 }
16
17 /// The kebab-case code.
18 #[must_use]
19 pub const fn as_str(self) -> &'static str {
20 self.0
21 }
22}
23
24impl fmt::Display for ErrorCode {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 f.write_str(self.0)
27 }
28}