leptos_struct_table/
row_reader.rs1use crate::loaded_rows::RowState;
2use std::cell::RefCell;
3use std::rc::Rc;
4
5#[derive(Clone)]
8pub struct RowReader<Row: Send + Sync + 'static> {
9 pub(crate) get_loaded_rows: LoadedRowsGetter<Row>,
10}
11
12pub type LoadedRowsGetter<Row> = Rc<RefCell<Box<dyn Fn(usize) -> RowState<Row>>>>;
13
14impl<Row: Send + Sync + 'static> Default for RowReader<Row> {
15 fn default() -> Self {
16 Self {
17 get_loaded_rows: Rc::new(RefCell::new(Box::new(|_| RowState::Placeholder))),
18 }
19 }
20}
21
22impl<Row: Send + Sync + 'static> RowReader<Row> {
23 pub fn cached_row(&self, index: usize) -> RowState<Row> {
25 (*self.get_loaded_rows.borrow())(index)
26 }
27}