Initial commit
Signed-off-by: Marko Korhonen <marko.korhonen@reekynet.com>
This commit is contained in:
commit
5f81577b83
7 changed files with 398 additions and 0 deletions
22
src/fs.rs
Normal file
22
src/fs.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use std::fs::{remove_file, File};
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn write(path: &PathBuf, contents: String) -> std::io::Result<()> {
|
||||
let mut file = File::create(path)?;
|
||||
file.write_all(contents.as_bytes())?;
|
||||
file.sync_data()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read(path: &PathBuf) -> std::io::Result<String> {
|
||||
let mut file = File::open(path)?;
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
Ok(contents)
|
||||
}
|
||||
|
||||
pub fn remove(path: &PathBuf) -> std::io::Result<()> {
|
||||
remove_file(path)?;
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue