only_diagnostic/code.rs
1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
4pub struct DiagnosticCode(String);
5
6impl DiagnosticCode {
7 /// Creates a stable diagnostic code.
8 ///
9 /// Args:
10 /// value: Code text shared across hosts.
11 ///
12 /// Returns:
13 /// New diagnostic code wrapper.
14 pub fn new(value: impl Into<String>) -> Self {
15 Self(value.into())
16 }
17
18 /// Returns the raw diagnostic code text.
19 ///
20 /// Args:
21 /// None.
22 ///
23 /// Returns:
24 /// Borrowed diagnostic code string.
25 pub fn as_str(&self) -> &str {
26 &self.0
27 }
28}
29
30impl fmt::Display for DiagnosticCode {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 f.write_str(self.as_str())
33 }
34}