pub struct CSVFile {
pub file_data: Vec<String>,
pub header: String,
pub num_rows: usize,
pub num_cols: usize,
pub file_path: String,
pub max_col_lengths: Vec<usize>,
}Fields§
§file_data: Vec<String>§header: String§num_rows: usize§num_cols: usize§file_path: String§max_col_lengths: Vec<usize>Implementations§
Trait Implementations§
Source§impl FileDataUtils for CSVFile
impl FileDataUtils for CSVFile
Source§fn display_file(
&self,
start_index: Option<usize>,
end_index: Option<usize>,
) -> Result<(), Box<dyn Error>>
fn display_file( &self, start_index: Option<usize>, end_index: Option<usize>, ) -> Result<(), Box<dyn Error>>
Displays a portion of the CSV file, including headers and specified rows.
§Arguments
start_index- The optional starting index for the displayed rows. Default is 1.end_index- The optional ending index for the displayed rows. Default is the total number of rows.
§Errors
Returns an error if the provided indices are invalid.
Source§fn delete_entry(
&mut self,
row_index: usize,
col_index: usize,
) -> Result<(), Box<dyn Error>>
fn delete_entry( &mut self, row_index: usize, col_index: usize, ) -> Result<(), Box<dyn Error>>
Deletes the specified entry at the intersection of the provided row and column indices.
§Arguments
row_index- The index of the row containing the entry to be deleted.col_index- The index of the column containing the entry to be deleted.
§Errors
Returns an error if the provided row or column index is invalid, or if the existing entry is NULL(_).
Source§fn modify_row(
&mut self,
row_index: usize,
row_data: String,
) -> Result<(), Box<dyn Error>>
fn modify_row( &mut self, row_index: usize, row_data: String, ) -> Result<(), Box<dyn Error>>
Modifies the specified row with the provided row data.
§Arguments
row_index- The index of the row to be modified.row_data- A string containing the new data for the specified row, separated by commas.
§Errors
Returns an error if the provided row index is invalid, or if the row data has an incorrect number of entries.
Source§fn modify_column(
&mut self,
col_index: usize,
new_entry: String,
) -> Result<(), Box<dyn Error>>
fn modify_column( &mut self, col_index: usize, new_entry: String, ) -> Result<(), Box<dyn Error>>
Modifies the specified column with the provided new entry values.
§Arguments
col_index- The index of the column to be modified.new_entry- A string containing the new values for the specified column, separated by commas.
§Errors
Returns an error if the provided column index is invalid, or if the new entry has an incorrect number of values.
Source§fn update_entry(
&mut self,
row_index: usize,
col_index: usize,
new_entry: String,
) -> Result<(), Box<dyn Error>>
fn update_entry( &mut self, row_index: usize, col_index: usize, new_entry: String, ) -> Result<(), Box<dyn Error>>
Updates the specified entry in the CSV file with a new value.
§Arguments
row_index- The index of the row containing the entry to be updated.col_index- The index of the column containing the entry to be updated.new_entry- A string representing the new value for the specified entry.
§Errors
Returns an error if the provided row or column index is invalid.
Source§fn sorted_display(&self) -> Result<(), Box<dyn Error>>
fn sorted_display(&self) -> Result<(), Box<dyn Error>>
Displays the CSV file with rows sorted in ascending order.
This function creates a temporary CSV structure, sorts its rows, and displays the result.
§Errors
Returns an error if there is an issue with displaying the sorted file.
Source§fn merge_files(&mut self, other: &Self) -> Result<(), Box<dyn Error>>
fn merge_files(&mut self, other: &Self) -> Result<(), Box<dyn Error>>
Merges the content of another CSV file into the current loaded CSV file.
This function appends the rows from the specified CSV file (other) to the current CSV file.
The two files must have the same number of columns for a successful merge.
§Arguments
other- A reference to another CSV file to be merged into the current file.
§Errors
Returns an error if the two files have incompatible dimensions or if there is any issue with the merge.
Source§fn add_row(&mut self, row_data: String) -> Result<(), Box<dyn Error>>
fn add_row(&mut self, row_data: String) -> Result<(), Box<dyn Error>>
Adds a new row to the CSV file.
This function appends a new row with the specified data to the end of the CSV file.
§Arguments
row_data- A string containing the data for the new row, with values separated by commas.
§Errors
Returns an error if the number of entries in the provided row data is not equal to the total number of columns in the CSV file.