use std::cell::RefCell;
use crate::{MarkdownExt, Share, FrontMatter};

/// A naive [`MarkdownExt`] implementor.
///
/// [`MarkdownExt`]: trait.MarkdownExt.html
#[derive(new)]
pub struct Raw<I, T>
where
    I: Iterator<Item = T>,
{
    frontmatter: Share<RefCell<Option<FrontMatter>>>,
    iter: I,
}

impl<I, T> Iterator for Raw<I, T>
where
    I: Iterator<Item = T>,
{
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        self.iter.next()
    }
}

impl<I, T> MarkdownExt<T> for Raw<I, T>
where
    I: Iterator<Item = T>,
{
    fn frontmatter(&mut self) -> &mut Share<RefCell<Option<FrontMatter>>> {
        &mut self.frontmatter
    }
}
