acdc_parser/model/
attribution.rs1use std::ops::Deref;
2
3use serde::{Serialize, ser::Serializer};
4
5use super::inlines::InlineNode;
6
7#[derive(Clone, Debug, Default, PartialEq)]
17#[non_exhaustive]
18pub struct Attribution(Vec<InlineNode>);
19
20impl Serialize for Attribution {
21 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
22 where
23 S: Serializer,
24 {
25 self.0.serialize(serializer)
26 }
27}
28
29impl Attribution {
30 #[must_use]
32 pub fn new(inlines: Vec<InlineNode>) -> Self {
33 Self(inlines)
34 }
35
36 #[must_use]
38 pub fn is_empty(&self) -> bool {
39 self.0.is_empty()
40 }
41
42 #[must_use]
44 pub fn len(&self) -> usize {
45 self.0.len()
46 }
47}
48
49impl From<Vec<InlineNode>> for Attribution {
50 fn from(inlines: Vec<InlineNode>) -> Self {
51 Self(inlines)
52 }
53}
54
55impl AsRef<[InlineNode]> for Attribution {
56 fn as_ref(&self) -> &[InlineNode] {
57 &self.0
58 }
59}
60
61impl Deref for Attribution {
62 type Target = [InlineNode];
63
64 fn deref(&self) -> &Self::Target {
65 &self.0
66 }
67}
68
69impl<'a> IntoIterator for &'a Attribution {
70 type Item = &'a InlineNode;
71 type IntoIter = std::slice::Iter<'a, InlineNode>;
72
73 fn into_iter(self) -> Self::IntoIter {
74 self.0.iter()
75 }
76}
77
78#[derive(Clone, Debug, Default, PartialEq)]
87#[non_exhaustive]
88pub struct CiteTitle(Vec<InlineNode>);
89
90impl Serialize for CiteTitle {
91 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
92 where
93 S: Serializer,
94 {
95 self.0.serialize(serializer)
96 }
97}
98
99impl CiteTitle {
100 #[must_use]
102 pub fn new(inlines: Vec<InlineNode>) -> Self {
103 Self(inlines)
104 }
105
106 #[must_use]
108 pub fn is_empty(&self) -> bool {
109 self.0.is_empty()
110 }
111
112 #[must_use]
114 pub fn len(&self) -> usize {
115 self.0.len()
116 }
117}
118
119impl From<Vec<InlineNode>> for CiteTitle {
120 fn from(inlines: Vec<InlineNode>) -> Self {
121 Self(inlines)
122 }
123}
124
125impl AsRef<[InlineNode]> for CiteTitle {
126 fn as_ref(&self) -> &[InlineNode] {
127 &self.0
128 }
129}
130
131impl Deref for CiteTitle {
132 type Target = [InlineNode];
133
134 fn deref(&self) -> &Self::Target {
135 &self.0
136 }
137}
138
139impl<'a> IntoIterator for &'a CiteTitle {
140 type Item = &'a InlineNode;
141 type IntoIter = std::slice::Iter<'a, InlineNode>;
142
143 fn into_iter(self) -> Self::IntoIter {
144 self.0.iter()
145 }
146}