redispatch_xml/types/attr_v.rs
1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5/// Generic wrapper for the ENTSO-E/BDEW attr-v pattern:
6///
7/// ```xml
8/// <ElementName v="value"/>
9/// ```
10///
11/// The `v` attribute holds the actual value. This pattern appears in all
12/// ENTSO-E-derived and most BDEW XML documents (ActivationDocument,
13/// PlannedResourceScheduleDocument, AcknowledgementDocument,
14/// NetworkConstraintDocument, Kostenblatt).
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct AttrV<T> {
17 /// The element value, stored in the `v` XML attribute.
18 #[serde(rename = "@v")]
19 pub v: T,
20}
21
22impl<T> AttrV<T> {
23 /// Create a new `AttrV` wrapper.
24 pub fn new(v: T) -> Self {
25 Self { v }
26 }
27}
28
29impl<T: Clone> AttrV<T> {
30 /// Unwrap and clone the inner value.
31 pub fn value(&self) -> T {
32 self.v.clone()
33 }
34}
35
36impl<T> From<T> for AttrV<T> {
37 fn from(v: T) -> Self {
38 Self { v }
39 }
40}
41
42impl<T: fmt::Display> fmt::Display for AttrV<T> {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 self.v.fmt(f)
45 }
46}
47
48/// Wrapper for elements whose value is in a `v` attribute **and** that have
49/// an additional `codingScheme` attribute:
50///
51/// ```xml
52/// <SenderIdentification v="4045399000008" codingScheme="A10"/>
53/// ```
54///
55/// Used for market participant IDs (`SenderIdentification`,
56/// `ReceiverIdentification`, `ResourceProvider`) and control zone references
57/// (`ConnectingArea`, `AcquiringArea`) in the attr-v document family.
58#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
59pub struct AttrVWithScheme<T, S = crate::types::CodingScheme> {
60 /// The element value.
61 #[serde(rename = "@v")]
62 pub v: T,
63 /// The coding scheme qualifier.
64 #[serde(rename = "@codingScheme")]
65 pub coding_scheme: S,
66}
67
68impl<T, S> AttrVWithScheme<T, S> {
69 /// Create a new `AttrVWithScheme` wrapper.
70 pub fn new(v: T, coding_scheme: S) -> Self {
71 Self { v, coding_scheme }
72 }
73}
74
75/// Wrapper for IEC 62325 simpleContent elements: text content with an
76/// additional `codingScheme` attribute:
77///
78/// ```xml
79/// <mRID codingScheme="A10">4045399000008</mRID>
80/// ```
81///
82/// Used in Kaskade, Unavailability_MarketDocument, and
83/// StatusRequest_MarketDocument.
84#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
85pub struct SimpleContent<T, S = crate::types::CodingScheme> {
86 /// Text content of the element.
87 #[serde(rename = "$text")]
88 pub value: T,
89 /// Coding scheme qualifier attribute.
90 #[serde(rename = "@codingScheme")]
91 pub coding_scheme: S,
92}
93
94impl<T, S> SimpleContent<T, S> {
95 /// Create a new `SimpleContent` wrapper.
96 pub fn new(value: T, coding_scheme: S) -> Self {
97 Self {
98 value,
99 coding_scheme,
100 }
101 }
102}