CSVFile

Struct CSVFile 

Source
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§

Source§

impl CSVFile

Source

pub fn new(file_path: &String) -> Self

Source

pub fn write_to_file(&self)

Trait Implementations§

Source§

impl Clone for CSVFile

Source§

fn clone(&self) -> CSVFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CSVFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CSVFile

Source§

fn default() -> CSVFile

Returns the “default value” for a type. Read more
Source§

impl FileDataUtils for CSVFile

Source§

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_row(&mut self, row_index: usize) -> Result<(), Box<dyn Error>>

Deletes the specified row from the CSV file.

§Arguments
  • row_index - The index of the row to be deleted.
§Errors

Returns an error if the provided row index is invalid.

Source§

fn delete_column(&mut self, col_index: usize) -> Result<(), Box<dyn Error>>

Deletes the specified column from the CSV file.

§Arguments
  • col_index - The index of the column to be deleted.
§Errors

Returns an error if the provided column index is invalid.

Source§

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>>

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>>

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>>

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>>

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>>

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>>

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.

Source§

fn add_column(&mut self, new_entry: String) -> Result<(), Box<dyn Error>>

Adds a new column to the CSV file with the provided entries.

§Arguments
  • new_entry - A string containing comma-separated values for the new column.
§Errors

Returns an error if the number of entries in new_entry is not equal to the (total number of rows + 1) in the CSV file.

Source§

fn display_column(&self, col_index: usize) -> Result<(), Box<dyn Error>>

Displays the specified column in the CSV file.

§Arguments
  • col_index - The index of the column to be displayed.
§Errors

Returns an error if the column index is invalid (greater than the total number of columns or less than 1).

Source§

fn display_row(&self, row_index: usize) -> Result<(), Box<dyn Error>>

Displays the specified row in the CSV file.

§Arguments
  • row_index - The index of the row to be displayed.
§Errors

Returns an error if the row index is invalid (greater than the total number of rows or less than 1).

Source§

impl PartialEq for CSVFile

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.