use crate::{Span, strings::CowStr};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Content<'src> {
original: Span<'src>,
pub(crate) rendered: CowStr<'src>,
}
impl<'src> Content<'src> {
pub(crate) fn from_filtered<T: AsRef<str>>(span: Span<'src>, filtered: T) -> Self {
Self {
original: span,
rendered: filtered.as_ref().to_string().into(),
}
}
pub fn original(&self) -> Span<'src> {
self.original
}
pub fn rendered(&'src self) -> &'src str {
self.rendered.as_ref()
}
pub fn is_empty(&self) -> bool {
self.rendered.as_ref().is_empty()
}
}
impl<'src> From<Span<'src>> for Content<'src> {
fn from(span: Span<'src>) -> Self {
Self {
original: span,
rendered: CowStr::from(span.data()),
}
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
mod is_empty {
#[test]
fn basic_empty_span() {
let content = crate::content::Content::from(crate::Span::default());
assert!(content.is_empty());
}
#[test]
fn basic_non_empty_span() {
let content = crate::content::Content::from(crate::Span::new("blah"));
assert!(!content.is_empty());
}
}
}