use docspec_core::{Event, EventSource, Result};
#[cfg(feature = "html")]
use docspec_html_reader::HtmlReader;
#[cfg(feature = "markdown")]
use docspec_markdown_reader::MarkdownReader;
use crate::format::InputFormat;
pub enum AnyReader<'a> {
#[cfg(feature = "html")]
Html(HtmlReader<'a>),
#[cfg(feature = "markdown")]
Markdown(MarkdownReader<'a>),
#[cfg(not(any(feature = "markdown", feature = "html")))]
_Phantom(std::marker::PhantomData<&'a ()>),
}
impl<'a> AnyReader<'a> {
#[inline]
#[must_use]
pub fn new(format: InputFormat, input: &'a str) -> Self {
#[cfg(not(any(feature = "markdown", feature = "html")))]
{
let _ = input;
match format {}
}
#[cfg(any(feature = "markdown", feature = "html"))]
match format {
#[cfg(feature = "html")]
InputFormat::Html => Self::Html(HtmlReader::new(input)),
#[cfg(feature = "markdown")]
InputFormat::Markdown => Self::Markdown(MarkdownReader::new(input)),
}
}
}
impl EventSource for AnyReader<'_> {
#[inline]
fn next_event(&mut self) -> Result<Option<Event>> {
match self {
#[cfg(feature = "html")]
Self::Html(r) => r.next_event(),
#[cfg(feature = "markdown")]
Self::Markdown(r) => r.next_event(),
#[cfg(not(any(feature = "markdown", feature = "html")))]
Self::_Phantom(_) => Ok(None),
}
}
}