leptos_struct_table/
row_reader.rsuse crate::loaded_rows::RowState;
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Clone)]
pub struct RowReader<Row: Send + Sync + 'static> {
pub(crate) get_loaded_rows: LoadedRowsGetter<Row>,
}
pub type LoadedRowsGetter<Row> = Rc<RefCell<Box<dyn Fn(usize) -> RowState<Row>>>>;
impl<Row: Send + Sync + 'static> Default for RowReader<Row> {
fn default() -> Self {
Self {
get_loaded_rows: Rc::new(RefCell::new(Box::new(|_| RowState::Placeholder))),
}
}
}
impl<Row: Send + Sync + 'static> RowReader<Row> {
pub fn cached_row(&self, index: usize) -> RowState<Row> {
(*self.get_loaded_rows.borrow())(index)
}
}