Struct FileAPI

Source
pub struct FileAPI {
    pub path: String,
    /* private fields */
}
Expand description

A structure of file modified API. This class is used to change, read, write, remove a file in the project.

You can custom the split character by using split function.

To initialize the FileAPI, you can use the from function.

§Example

create a new FileAPI instance:

use self::simple_file_manager::fileapi::FileAPI;

let file = FileAPI::from("filename.gph");

collect a Reader type (same with Builder, Changer):

use self::simple_file_manager::fileapi::FileAPI;

// custom the split character.
let file = FileAPI::from("filename.gph").split(',');
let reader = file.reader();

// read the header of the file
let header = reader.read_header::<usize>(1)[0].clone();

assert_eq!(header, vec![1, 2, 3]);

then you will receive a Vec recording the value in the first line, which are also parsed to usize type.

Fields§

§path: String

Implementations§

Source§

impl FileAPI

Source

pub fn from(path: &str) -> FileAPI

Initialize the FileAPI, you can use the [from] function.

§Example

create a new FileAPI instance:

use self::simple_file_manager::fileapi::FileAPI;

let file = FileAPI::from("filename.gph");
Source

pub fn split(self, split: char) -> Self

Set the split character for all process (except read_csv). The default character is ’ ’ (whitespace).

§Example
use self::simple_file_manager::fileapi::FileAPI;

let file = FileAPI::from("filename.gph").split(',');
// the values will divided by ','.
let reader = file.reader();
let body = reader.read_body::<usize>(1, 1);

assert_eq!(body, vec![vec![4, 5, 6], vec![7, 8, 9]]);
Source

pub fn reader(&self) -> Reader<'_>

Get a Reader object for reading several values of the same file in succession.

§Example

collect a Reader type (same with Builder, Changer):

use self::simple_file_manager::fileapi::FileAPI;

let file = FileAPI::from("filename.gph");
let reader = file.reader();

// read the header of the file
let header = reader.read_header::<usize>(1)[0].clone();

assert_eq!(header, vec![1, 2, 3]);

then you will receive a Vec recording the value in the first line, which are also parsed to usize type.

Source

pub fn changer(&self) -> Changer<'_>

Get a Changer object for modifying several values of the same file in succession.

§Example

collect a Changer type (same with Builder, Reader):

use self::simple_file_manager::fileapi::FileAPI;

let file = FileAPI::from("filename.gph").split(',');
let changer = file.changer();

// change the value in the 2th line and 2th row to value '123':
// you can consecutive change values:
changer.change_value(2, 2, "123")
    .change_value(3, 2, "567")
    .change_value(4, 2, "560")
    .execute();  // after modifying the value, you will need to execute your changes.
Source

pub fn builder(&self) -> Builder<'_>

Get a Builder object for writing several values for a new file in succession.

§Example

collect a Builder type (same with Changer, Reader):

use self::simple_file_manager::fileapi::FileAPI;

let file = FileAPI::from("filename.gph");
let mut builder = file.builder();

// write a line:
// you can consecutive write lines:
builder.write_line("This is the second line.")
    .write_line("This is the third line.")
    .write_line("This is the forth line.")
    .execute(); // you will also need to execute your changes:
Source

pub fn remove(&self)

A function to remove the file and delete the object.

§Example
use self::simple_file_manager::fileapi::FileAPI;

FileAPI::from("filename.gph").remove();
Source

pub fn is_exist(&self) -> bool

A function to check if the file exist.

§Example
use self::simple_file_manager::fileapi::FileAPI;

let file = FileAPI::from("filename.gph");
if file.is_exist() {
    file.remove();
};

Trait Implementations§

Source§

impl Clone for FileAPI

Source§

fn clone(&self) -> Self

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

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.