Skip to main content

core_invoice/
code.rs

1//! Verbatim [`Code`]. List membership is a rule (BR-CL-*), not a constructor.
2
3use std::fmt;
4
5/// Verbatim code. Membership is a rule (BR-CL-*), not a constructor.
6#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct Code(String);
8
9impl Code {
10    /// Verbatim code as written. No list check.
11    pub fn new(value: impl Into<String>) -> Self {
12        Self(value.into())
13    }
14
15    /// Code as written.
16    pub fn as_str(&self) -> &str {
17        &self.0
18    }
19
20    /// True when empty or whitespace-only.
21    pub fn is_empty(&self) -> bool {
22        self.0.trim().is_empty()
23    }
24}
25
26impl fmt::Display for Code {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        self.0.fmt(f)
29    }
30}
31
32impl From<&str> for Code {
33    fn from(value: &str) -> Self {
34        Self::new(value)
35    }
36}