ced

Struct Processor

Source
pub struct Processor { /* private fields */ }
Expand description

Csv processor

Processor has multiple pages which can be accessed with page_name. Processor has currently selected page which name can be accessed with get_cursor method.

Implementations§

Source§

impl Processor

Main loop struct for interactive csv editing

Source

pub fn execute_command(&mut self, command: &Command) -> CedResult<()>

Execute given command

Source

pub fn limit_column_from_args( &mut self, page_name: &str, args: &[String], ) -> CedResult<()>

Source

pub fn execute_from_file(&mut self, args: &Vec<String>) -> CedResult<()>

Source§

impl Processor

Source

pub fn new() -> Self

Create empty processor

Source

pub fn change_cursor(&mut self, page_name: &str) -> bool

Change current cusor(page)

This doesn’t affect page itself but change cursor.

  • This returns boolean value whether change succeeded or not
Source

pub fn get_cursor(&self) -> Option<String>

Get current cursor (page_name)

Source

pub fn add_page( &mut self, page: &str, data: &str, has_header: bool, line_ending: Option<char>, raw_mode: bool, ) -> CedResult<()>

Add a new page

§Args
  • page : Page name to create
  • data : Csv data to store inside a page
  • has_header : Whether csv data has header or not.
  • line_ending : Optional line_ending configuration.
  • raw_mode : This decides whether page be data or array
Source

pub fn remove_page(&mut self, page_name: &str)

Remove page with given name

This doesn’t panic and silent do nothing if page name is non-existent

Source

pub fn contains_page(&self, page: &str) -> bool

Check if processor contains a page

Source

pub fn drop_pages(&mut self) -> CedResult<()>

Drop all data from processor

Source

pub fn import_from_file( &mut self, path: impl AsRef<Path>, has_header: bool, line_ending: Option<char>, raw_mode: bool, ) -> CedResult<()>

Import file content as page

This will drop the page if given page name already exists.

§Args
  • path: File path to import from
  • has_header : Whether csv file has header or not
  • line_ending : Optional line_ending of csv
  • raw_mode : Whether imported as data or array
Source

pub fn write_to_file(&self, page: &str, file: impl AsRef<Path>) -> CedResult<()>

Write all page’s content into a file

Source

pub fn overwrite_to_file(&self, page: &str, cache: bool) -> CedResult<bool>

Overwrite virtual data’s content into a imported file

  • cache : whether to backup original file’s content into temp directory
Source

pub fn edit_cell( &mut self, page: &str, x: usize, y: usize, input: &str, ) -> CedResult<()>

Edit a cell by given coordinate

Source

pub fn edit_column( &mut self, page: &str, column: &str, input: &str, ) -> CedResult<()>

Edit a column by given coordinate

This overwrite all column values with given input

Source

pub fn edit_row( &mut self, page: &str, row_index: usize, input: &[Option<Value>], ) -> CedResult<()>

Edit a row with values

This assumes given input accords with order of a target record.

§Args
  • page : Page name
  • row_index : Target row
  • input : Inputs are array of options. Some will overwrite and none will not.
Source

pub fn set_row( &mut self, page: &str, row_index: usize, input: &[Value], ) -> CedResult<()>

Set a row with given values

This assumes given input accords with order of a target record. This method overwrite an entire row with given values.

Source

pub fn set_row_from_string_array( &mut self, page: &str, row_index: usize, input: &[impl AsRef<str>], ) -> CedResult<()>

Set a row with given string array

This assumes given input accords with order of a target record. This method overwrite an entire row with given values.

Source

pub fn add_row( &mut self, page: &str, row_index: usize, values: Option<&[Value]>, ) -> CedResult<()>

Add a new row

This assumes given input accords with order of a target record.

§Args
  • page: Target page
  • row_index : Target row
  • values : Option. “None” will converted as default values.
Source

pub fn add_row_from_string_array( &mut self, page: &str, row_index: usize, src: &[impl AsRef<str>], ) -> CedResult<()>

Add a new row but from array of strings

This assumes given input accords with order of a target record.

§Args
  • page: Target page
  • row_index : Target row
  • values : Option. “None” will converted as default values.
Source

pub fn add_column( &mut self, page: &str, column_index: usize, column_name: &str, column_type: ValueType, limiter: Option<ValueLimiter>, placeholder: Option<Value>, ) -> CedResult<()>

Add a new column into a page

Source

pub fn remove_row(&mut self, page: &str, row_index: usize) -> CedResult<bool>

Remove a row from a page

Source

pub fn remove_column( &mut self, page: &str, column_index: usize, ) -> CedResult<()>

Remove a column from a page

Source

pub fn add_column_array( &mut self, page: &str, columns: &[impl AsRef<str>], ) -> CedResult<()>

Add columns into a page

This method dosn’t require any column configurators

Source

pub fn move_row( &mut self, page: &str, src: usize, target: usize, ) -> CedResult<()>

Move a rom from an index to a target index

Source

pub fn move_column( &mut self, page: &str, src: usize, target: usize, ) -> CedResult<()>

Move a column from an index to a target index

Source

pub fn rename_column( &mut self, page: &str, column: &str, new_name: &str, ) -> CedResult<()>

Rename a column into a new name

Source

pub fn export_schema(&self, page: &str) -> CedResult<String>

Export page’s schema

Source

pub fn set_schema( &mut self, page: &str, path: impl AsRef<Path>, panic: bool, ) -> CedResult<()>

Apply schema into a given page

§Args
  • page : Page name
  • path : Schema file path
  • panic : Whether to panic if current value fails to qualify schema. If not every unqualified values are overwritten to default qualifying values.
Source

pub fn set_limiter( &mut self, page: &str, column: &str, limiter: &ValueLimiter, panic: bool, ) -> CedResult<()>

Set a limiter to a column

§Args
  • page : Page name
  • column : Target column name(index)
  • limiter : A limiter to apply to column
  • panic : Whether to panic if current value fails to qualify liimter. If not, every unqualified values are overwritten to default qualifying values.
Source

pub fn get_row_count(&self, page: &str) -> CedResult<usize>

Source

pub fn get_column_count(&self, page: &str) -> CedResult<usize>

Source

pub fn last_row_index(&self, page: &str) -> CedResult<usize>

Get last row index

Source

pub fn last_column_index(&self, page: &str) -> CedResult<usize>

Get last column index

Source

pub fn get_page_as_string(&self, page: &str) -> CedResult<String>

Get virtual data as string form

Source

pub fn get_cell( &self, page: &str, row_index: usize, column_index: usize, ) -> CedResult<Option<&Value>>

Get cell from page

This fails when page or coordinate doesn’t exist

Source

pub fn get_column( &self, page: &str, column_index: usize, ) -> CedResult<Option<&Column>>

Get column from page

This fails when either page or column doesn’t exist

Source

pub fn get_column_by_name( &self, page: &str, column_name: &str, ) -> CedResult<Option<&Column>>

Get column from page by name

This fails when either page or column doesn’t exist

Trait Implementations§

Source§

impl Default for Processor

Source§

fn default() -> Self

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

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