Function rs_utils::file::is_file
[−]
[src]
pub fn is_file(file_path: &Path) -> Result<bool, Error>
If this returns true then std::fs::File::create
will not fail
with "is a directory" error.
This is not the same as std::path::Path::is_file
which also
tests whether the file actually exists.
Examples
assert!(is_file (Path::new ("path/to/file")).unwrap()); assert!(!is_file (Path::new ("path/to/directory/")).unwrap()); assert!(!is_file (Path::new ("..")).unwrap());
Errors
- Invalid unicode:
use std::os::unix::ffi::OsStrExt; let garbage = [192u8, 192u8, 192u8, 192u8]; let garbage_path = Path::new (OsStr::from_bytes (&garbage)); let e = is_file (&garbage_path).err().unwrap(); assert_eq!(e.kind(), ErrorKind::InvalidInput); assert_eq!(e.description(), "not valid unicode");