use std::marker::PhantomData;
use crate::{
grid::records::{ExactRecords, Records, Resizable},
settings::{location::Location, TableOption},
};
#[derive(Debug)]
pub struct Remove<L, Target> {
locator: L,
target: PhantomData<Target>,
}
impl<L> Remove<L, TargetColumn> {
pub fn column(locator: L) -> Self {
Self {
locator,
target: PhantomData,
}
}
}
impl<L> Remove<L, TargetRow> {
pub fn row(locator: L) -> Self {
Self {
locator,
target: PhantomData,
}
}
}
#[derive(Debug)]
pub struct TargetRow;
#[derive(Debug)]
pub struct TargetColumn;
impl<L, R, D, C> TableOption<R, C, D> for Remove<L, TargetColumn>
where
L: Location<R, Coordinate = usize>,
R: Records + Resizable,
{
fn change(mut self, records: &mut R, _: &mut C, _: &mut D) {
let columns = self.locator.locate(records).into_iter().collect::<Vec<_>>();
let mut shift = 0;
for col in columns.into_iter() {
if col - shift > records.count_columns() {
continue;
}
records.remove_column(col - shift);
shift += 1;
}
}
}
impl<L, R, D, C> TableOption<R, C, D> for Remove<L, TargetRow>
where
L: Location<R, Coordinate = usize>,
R: ExactRecords + Resizable,
{
fn change(mut self, records: &mut R, _: &mut C, _: &mut D) {
let rows = self.locator.locate(records).into_iter().collect::<Vec<_>>();
let mut shift = 0;
for row in rows.into_iter() {
if row - shift > records.count_rows() {
continue;
}
records.remove_row(row - shift);
shift += 1;
}
}
}