1pub fn read_file(path: &str) -> String {
2 use std::fs;
3
4 let content = fs::read_to_string(path)
5 .expect("Error while reading file!");
6
7 return content.to_string();
8}
9
10pub fn write_file(path: &str, content: &str) -> bool {
11 use std::fs;
12
13 match fs::write(path, content) {
14 Err(err) => {
15 println!("{err}");
16 return true;
17 }
18
19 Ok(_) => {
20 return false;
21 }
22 }
23
24}
25
26pub fn append_file(path: &str, content: &str) -> bool {
27 let mut init_file = read_file(path);
28 init_file.push_str(content);
29
30 let err: bool = write_file(path, &init_file);
31
32 return err
33}
34
35pub fn create_file(path: &str) -> bool {
36 use std::fs;
37
38 match fs::File::create(path) {
39 Ok(_) => {
40 return false;
41 }
42 Err(err) => {
43 println!("{err}");
44 return true;
45 }
46
47 }
48}
49
50pub fn create_file_write(path: &str, content: &str) -> bool {
51 let err1 = create_file(path);
52 if err1 {
53 return true;
54 }
55 let err2: bool = write_file(path, content);
56
57 return err2
58}