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