use std::ops::Deref;
use serde::{Serialize, ser::Serializer};
use super::inlines::InlineNode;
#[derive(Clone, Debug, Default, PartialEq)]
#[non_exhaustive]
pub struct Attribution(Vec<InlineNode>);
impl Serialize for Attribution {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(serializer)
}
}
impl Attribution {
#[must_use]
pub fn new(inlines: Vec<InlineNode>) -> Self {
Self(inlines)
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
#[must_use]
pub fn len(&self) -> usize {
self.0.len()
}
}
impl From<Vec<InlineNode>> for Attribution {
fn from(inlines: Vec<InlineNode>) -> Self {
Self(inlines)
}
}
impl AsRef<[InlineNode]> for Attribution {
fn as_ref(&self) -> &[InlineNode] {
&self.0
}
}
impl Deref for Attribution {
type Target = [InlineNode];
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> IntoIterator for &'a Attribution {
type Item = &'a InlineNode;
type IntoIter = std::slice::Iter<'a, InlineNode>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
#[derive(Clone, Debug, Default, PartialEq)]
#[non_exhaustive]
pub struct CiteTitle(Vec<InlineNode>);
impl Serialize for CiteTitle {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(serializer)
}
}
impl CiteTitle {
#[must_use]
pub fn new(inlines: Vec<InlineNode>) -> Self {
Self(inlines)
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
#[must_use]
pub fn len(&self) -> usize {
self.0.len()
}
}
impl From<Vec<InlineNode>> for CiteTitle {
fn from(inlines: Vec<InlineNode>) -> Self {
Self(inlines)
}
}
impl AsRef<[InlineNode]> for CiteTitle {
fn as_ref(&self) -> &[InlineNode] {
&self.0
}
}
impl Deref for CiteTitle {
type Target = [InlineNode];
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> IntoIterator for &'a CiteTitle {
type Item = &'a InlineNode;
type IntoIter = std::slice::Iter<'a, InlineNode>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}