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
impl FileAPI
Sourcepub fn split(self, split: char) -> Self
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]]);
Sourcepub fn reader(&self) -> Reader<'_>
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.
Sourcepub fn changer(&self) -> Changer<'_>
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.
Sourcepub fn builder(&self) -> Builder<'_>
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: