use crate::hdu::header::extension::bintable::BinTable;
use std::fmt::Debug;
use std::io::{Read, Seek};
use super::data::TableData;
use super::DataValue;
#[derive(Debug)]
pub struct TableRowData<R> {
data: TableData<R>,
idx_row: usize,
}
impl<R> TableRowData<R> {
pub fn new(data: TableData<R>) -> Self {
Self { data, idx_row: 0 }
}
pub fn get_ctx(&self) -> &BinTable {
self.data.get_ctx()
}
pub fn get_row_idx(&self) -> usize {
self.idx_row
}
pub(crate) fn get_reader(&mut self) -> &mut R {
self.data.get_reader()
}
pub fn table_data(self) -> TableData<R> {
self.data
}
}
impl<R> Iterator for TableRowData<R>
where
R: Read + Seek + Debug,
{
type Item = Box<[DataValue]>;
fn next(&mut self) -> Option<Self::Item> {
let mut row_data = vec![];
while self.data.row_idx == self.idx_row {
row_data.push(self.data.next()?);
}
self.idx_row += 1;
Some(row_data.into_boxed_slice())
}
}