mirror of
https://github.com/veeso/termscp.git
synced 2026-07-24 00:27:19 +02:00
33 lines
718 B
Rust
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());
|
|
}
|
|
}
|