gen_file/
file.rs

1use std::io::Write;
2use std::fs;
3use crate::error::Error;
4
5pub fn write(line_set: Vec<String>, path: &str) -> Result<(), Error> {
6   let mut file = fs::OpenOptions::new().write(true).create(true).truncate(true).open(path)?;
7   for line in line_set {
8       writeln!(file, "{}", line.as_str().trim_end())?;
9   }
10   Ok(())
11}
12
13pub fn create(content: String, path: &str) -> Result<(), Error> {
14   let mut file = fs::OpenOptions::new().write(true).create(true).truncate(true).open(path)?;
15   Ok(write!(file, "{}", content)?)
16}
17
18pub fn delete(path: &str) -> Result<(), Error> {
19   Ok(fs::remove_file(path)?)
20}
21
22pub fn read(path: &str) -> Result<String, Error> {
23   Ok(fs::read_to_string(path)?)
24}
25
26#[cfg(test)]
27#[path = "../tests/unit_tests/file.rs"]
28pub mod test;