Files
termscp/src/utils/file.rs
Christian Visintin 9009002b6e debug log belongs in cache directory not config directory (#179)
* log files are now written to cache dir instead of config dir

* lint

* fmt
2023-05-09 15:32:42 +02:00

33 lines
718 B
Rust

//! ## File
//!
//! `file` is the module which exposes file related utilities
use std::fs::File;
use std::fs::OpenOptions;
use std::io;
use std::path::Path;
/// Open file provided as parameter
pub fn open_file<P>(filename: P, create: bool, write: bool, append: bool) -> io::Result<File>
where
P: AsRef<Path>,
{
OpenOptions::new()
.create(create)
.write(write)
.append(append)
.truncate(!append)
.open(filename)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_utils_file_open() {
let tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
assert!(open_file(tmpfile.path(), true, true, true).is_ok());
}
}