use std::fmt;
use std::ops::Deref;

use crate::chopper::error::Result;
use crate::chopper::types::{Header, Row};

pub trait Source: Send + Iterator<Item = Result<Box<Row>>> {
    fn header(&self) -> &Header;
}

impl Source for Box<dyn Source> {
    #[inline]
    fn header(&self) -> &Header {
        Deref::deref(self).header()
    }
}

//TODO better debug format?
impl fmt::Debug for dyn Source {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Source[{:?}]", self.header().field_names())
    }
}
