dcsv/
vcont.rs

1//! VCont is a generic trait for various virtual csv structs
2
3use crate::{DcsvResult, Value};
4
5/// Generic trait over both virtual_data and virtual_array
6///
7/// This provides some genral methods over csv value manipulation
8pub trait VCont {
9    /// Create empty virtual container
10    fn new() -> Self;
11
12    /// Move a given row to a target row index
13    fn move_row(&mut self, src_index: usize, target_index: usize) -> DcsvResult<()>;
14
15    /// Move a given column to target column index
16    fn move_column(&mut self, src_index: usize, target_index: usize) -> DcsvResult<()>;
17
18    /// Rename a column
19    fn rename_column(&mut self, column_index: usize, new_name: &str) -> DcsvResult<()>;
20
21    /// Set values to a column
22    fn set_column(&mut self, column_index: usize, value: Value) -> DcsvResult<()>;
23
24    /// Edit a row
25    fn edit_row(&mut self, row_index: usize, values: &[Option<Value>]) -> DcsvResult<()>;
26
27    /// Set values to a row
28    ///
29    /// This assumes that given values accord to column's order.
30    fn set_row(&mut self, row_index: usize, values: &[Value]) -> DcsvResult<()>;
31
32    /// get cell data by coordinate
33    fn get_cell(&self, x: usize, y: usize) -> Option<&Value>;
34
35    /// Set cell value by coordinate
36    fn set_cell(&mut self, x: usize, y: usize, value: Value) -> DcsvResult<()>;
37
38    /// Insert a row to given index
39    fn insert_row(&mut self, row_index: usize, source: Option<&[Value]>) -> DcsvResult<()>;
40
41    /// Delete a row with given row_index
42    fn delete_row(&mut self, row_index: usize) -> bool;
43
44    /// Insert a column with given column informations
45    fn insert_column(&mut self, column_index: usize, column_name: &str) -> DcsvResult<()>;
46
47    /// Delete a column with given column index
48    fn delete_column(&mut self, column_index: usize) -> DcsvResult<()>;
49
50    /// Get total rows count
51    fn get_row_count(&self) -> usize;
52
53    /// Get total columns count
54    fn get_column_count(&self) -> usize;
55
56    /// Drop all data from virtual data
57    fn drop_data(&mut self);
58
59    /// Apply closure to all values
60    fn apply_all<F: FnMut(&mut Value)>(&mut self, f: F);
61}