Skip to main content

core_invoice/
code.rs

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