use super::{html, markdown_v2, Nesting};
use std::{
fmt::{self, Formatter},
ops::Deref,
};
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct Raw<T>(T);
pub fn raw<I, T>(iterator: I) -> Raw<I>
where
for<'a> &'a I: IntoIterator<Item = &'a T>,
T: Deref<Target = str>,
{
Raw(iterator)
}
impl<I, T> markdown_v2::Formattable for Raw<I>
where
for<'a> &'a I: IntoIterator<Item = &'a T>,
T: Deref<Target = str>,
{
fn format(&self, formatter: &mut Formatter, _: Nesting) -> fmt::Result {
(&self.0)
.into_iter()
.map(|x| formatter.write_str(&*x))
.collect()
}
}
impl<I, T> html::Formattable for Raw<I>
where
for<'a> &'a I: IntoIterator<Item = &'a T>,
T: Deref<Target = str>,
{
fn format(
&self,
formatter: &mut Formatter,
nesting: Nesting,
) -> fmt::Result {
markdown_v2::Formattable::format(self, formatter, nesting)
}
}