acdc_parser/model/
title.rs1use std::ops::Deref;
2
3use serde::{Serialize, ser::Serializer};
4
5use super::inlines::InlineNode;
6
7#[derive(Clone, Debug, Default, PartialEq)]
41#[non_exhaustive]
42pub struct Title<'a>(Vec<InlineNode<'a>>);
43
44impl Serialize for Title<'_> {
45 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
46 where
47 S: Serializer,
48 {
49 self.0.serialize(serializer)
50 }
51}
52
53pub type Subtitle<'a> = Title<'a>;
54
55impl<'a> Title<'a> {
56 #[must_use]
58 pub fn new(inlines: Vec<InlineNode<'a>>) -> Self {
59 Self(inlines)
60 }
61
62 #[must_use]
64 pub fn into_inlines(self) -> Vec<InlineNode<'a>> {
65 self.0
66 }
67
68 pub(crate) fn inlines_mut(&mut self) -> &mut [InlineNode<'a>] {
71 &mut self.0
72 }
73
74 #[must_use]
76 pub fn is_empty(&self) -> bool {
77 self.0.is_empty()
78 }
79
80 #[must_use]
82 pub fn len(&self) -> usize {
83 self.0.len()
84 }
85}
86
87impl<'a> From<Vec<InlineNode<'a>>> for Title<'a> {
88 fn from(inlines: Vec<InlineNode<'a>>) -> Self {
89 Self(inlines)
90 }
91}
92
93impl<'a> AsRef<[InlineNode<'a>]> for Title<'a> {
94 fn as_ref(&self) -> &[InlineNode<'a>] {
95 &self.0
96 }
97}
98
99impl<'a> Deref for Title<'a> {
100 type Target = [InlineNode<'a>];
101
102 fn deref(&self) -> &Self::Target {
103 &self.0
104 }
105}
106
107impl<'a, 'b> IntoIterator for &'b Title<'a> {
108 type Item = &'b InlineNode<'a>;
109 type IntoIter = std::slice::Iter<'b, InlineNode<'a>>;
110
111 fn into_iter(self) -> Self::IntoIter {
112 self.0.iter()
113 }
114}