use crate::ascii_table::AsciiTable;
#[cfg(feature = "tokio")]
use crate::ascii_table::OwnedAsciiRow;
use crate::hdu::HDU;
#[cfg(feature = "serde")]
use serde::Serialize;
#[cfg(feature = "serde")]
use serde::de::DeserializeOwned;
use std::error::Error;
use std::fmt;
pub trait AsciiTableHDU: HDU + fmt::Debug + Send + Sync {
fn read_table(&self) -> Result<AsciiTable, Box<dyn Error + Send + Sync>>;
#[cfg(feature = "serde")]
fn read_rows<T: DeserializeOwned + Send + Sync>(
&self,
) -> Result<Vec<T>, Box<dyn Error + Send + Sync>> {
Ok(crate::ascii_table::from_ascii_table(&self.read_table()?)?)
}
#[cfg(feature = "serde")]
fn set_rows<T: Serialize>(&mut self, rows: &T) -> Result<(), Box<dyn Error + Send + Sync>> {
self.set_table(&crate::ascii_table::to_ascii_table(rows)?)
}
fn set_table(&mut self, table: &AsciiTable) -> Result<(), Box<dyn Error + Send + Sync>>;
#[cfg(feature = "tokio")]
fn stream_table_rows_raw(
&self,
) -> Result<futures::stream::BoxStream<'_, OwnedAsciiRow>, Box<dyn Error + Send + Sync>>;
#[cfg(feature = "serde")]
#[cfg(feature = "tokio")]
fn stream_table_rows<T: DeserializeOwned + Send + Sync>(
&self,
) -> Result<futures::stream::BoxStream<'_, crate::Result<T>>, Box<dyn Error + Send + Sync>>
{
use futures::StreamExt;
Ok(self
.stream_table_rows_raw()?
.map(|row| crate::ascii_table::from_ascii_table_row(&row.row()))
.boxed())
}
}