This package allows you to write and read txt file with one line of code, rather then having to waste time and write 10-50 lines of code!
There are two ways to read a file. One reads a file line by line(read), one reads it as a string (read_one).
fn main() {
let data = txt_writer::ReadData {}
.read("path to your txt".to_string())
.expect("failed when reading");
for x in data {
println!("{}", x);
}
}
``` fn main() { let data = txtwriter::ReadData {} .readone("path to your txt".to_string()) .expect("failed when reading"); println!("{}", data); }
```
There are 2 ways to write data. If you want to create a txt OR overwrite data use this.
fn main() {
txt_writer::WriteData {}
.drop_replace(
"what you want to write to txt".to_string(),
"path to your txt".to_string(),
)
.expect("failed when writing");
}
use this one if you want to pass a &String value
``` fn main() { txtwriter::WriteData {} .replace( &"what you want to write to txt".tostring(), "path to your txt".to_string(), ) .expect("failed when writing"); }
```
NOTE THIS FUNCTION WILL RETURN AN ERROR IF THE TXT DOES NOT EXIST
use this one if you want to pass a String value
``` fn main(){ txtwriter::WriteData {} .dropadd( "what you want to write to txt".tostring(), "path to your txt".tostring(), ) .expect("failed when writing"); }
```
use this one if you want to pass a &String value
``` fn main() { txtwriter::WriteData {} .add( &"what you want to write to txt".tostring(), "path to your txt".to_string(), ) .expect("failed when writing"); }
```
``` fn main() { txtwriter::WriteData {} .dropreplace( "what you want to write to txt".tostring(), "src/data.txt".tostring(), ) .expect("failed when writing");
txt_writer::WriteData {}
.replace(
&"what you want to write to txt".to_string(),
"src/data.txt".to_string(),
)
.expect("failed when writing");
txt_writer::WriteData {}
.drop_add(
"what you want to write to txt".to_string(),
"src/data.txt".to_string(),
)
.expect("failed when writing");
txt_writer::WriteData {}
.add(
&"what you want to write to txt".to_string(),
"src/data.txt".to_string(),
)
.expect("failed when writing");
let data = txt_writer::ReadData {}
.read("src/data.txt".to_string())
.expect("failed when reading");
for x in data {
println!("{}", x);
}
let data = txt_writer::ReadData {}
.read_one("src/data.txt".to_string())
.expect("failed when reading");
println!("{}", data);
} ```