Skip to main content

core_invoice/
identifier.rs

1//! [`Identifier`] (value + optional scheme) and [`DocumentReference`] (content only).
2
3use std::fmt;
4
5/// Identifier.Type: content + optional scheme + optional scheme version.
6/// Lists are profile-scoped; this type does not require EAS.
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8pub struct Identifier {
9    /// Identifier content.
10    pub value: String,
11    /// Optional scheme identifier. Not required by this type.
12    pub scheme: Option<String>,
13    /// Optional scheme version identifier.
14    pub scheme_version: Option<String>,
15}
16
17impl Identifier {
18    /// Unschemed identifier.
19    pub fn new(value: impl Into<String>) -> Self {
20        Self {
21            value: value.into(),
22            scheme: None,
23            scheme_version: None,
24        }
25    }
26
27    /// Identifier with scheme, no version.
28    pub fn schemed(value: impl Into<String>, scheme: impl Into<String>) -> Self {
29        Self {
30            value: value.into(),
31            scheme: Some(scheme.into()),
32            scheme_version: None,
33        }
34    }
35
36    /// Identifier with scheme and scheme version.
37    pub fn with_version(
38        value: impl Into<String>,
39        scheme: impl Into<String>,
40        version: impl Into<String>,
41    ) -> Self {
42        Self {
43            value: value.into(),
44            scheme: Some(scheme.into()),
45            scheme_version: Some(version.into()),
46        }
47    }
48}
49
50/// Document reference (PO, contract, preceding invoice id). No scheme.
51#[derive(Debug, Clone, PartialEq, Eq, Hash)]
52pub struct DocumentReference(
53    /// Reference content. No scheme.
54    pub String,
55);
56
57impl DocumentReference {
58    /// Content-only document reference.
59    pub fn new(value: impl Into<String>) -> Self {
60        Self(value.into())
61    }
62
63    /// Reference as written.
64    pub fn as_str(&self) -> &str {
65        &self.0
66    }
67}
68
69impl fmt::Display for DocumentReference {
70    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71        self.0.fmt(f)
72    }
73}