Trait fdir::FileAttr

source ·
pub trait FileAttr: Sized {
Show 16 methods // Required methods fn as_path(&self) -> &Path; fn size(&self) -> u64; fn rename<T: AsRef<OsStr>>(&mut self, name: T) -> Result<()>; fn eq(&self, other: &Self) -> bool; fn copy_new<P: AsRef<Path>>(&self, path: P) -> RecoverResult<'_>; fn move_new<P: AsRef<Path>>(&mut self, path: P) -> RecoverResult<'_>; // Provided methods fn file_name(&self) -> Option<&OsStr> { ... } fn metadata(&self) -> Result<Metadata> { ... } fn parent(&self) -> Option<DirectoryInfo> { ... } fn permissions(&self) -> Result<Permissions> { ... } fn set_permissions(&self, perm: Permissions) -> Result<()> { ... } fn read_only(&self) -> Result<bool> { ... } fn set_readonly(&self, readonly: bool) -> Result<()> { ... } fn delete(self) -> Result<()> { ... } fn copy_to<P: AsRef<Path>>(&self, path: P) -> RecoverResult<'_> { ... } fn move_to<P: AsRef<Path>>(&mut self, path: P) -> RecoverResult<'_> { ... }
}

Required Methods§

source

fn as_path(&self) -> &Path

source

fn size(&self) -> u64

source

fn rename<T: AsRef<OsStr>>(&mut self, name: T) -> Result<()>

Rename a file or directory

Examples
use fdir::{FileAttr, FileInfo};
let mut file = FileInfo::create("foo.txt").unwrap();
file.rename("bar").unwrap();  // or bar.txt
assert_eq!(file.file_name(), Some("bar.txt".as_ref()))
source

fn eq(&self, other: &Self) -> bool

source

fn copy_new<P: AsRef<Path>>(&self, path: P) -> RecoverResult<'_>

Copy a file or directory to a new destination path

Examples
use fdir::{FileInfo, FileAttr};
let f = FileInfo::create("foo.txt").unwrap();
f.copy_new("test/bar.txt").unwrap();
assert!(FileInfo::open("test/bar.txt").is_ok())
Repairable Error

If the destination path already exists, return an error that can be recovered

Example
use fdir::{FileInfo, FileAttr};
FileInfo::create("test/foo.txt").unwrap();
let f = FileInfo::create("foo.txt").unwrap();

let res = f.copy_new("test/foo.txt");
assert!(res.is_err());
let res = f.copy_new("test/foo.txt").or_else(|e| e.try_recover());
assert!(res.is_ok())
source

fn move_new<P: AsRef<Path>>(&mut self, path: P) -> RecoverResult<'_>

Move a file or directory to a new destination path

Examples
use std::env::current_dir;
use fdir::{FileInfo, FileAttr};

let mut f = FileInfo::create("foo.txt").unwrap();
f.move_new("test/bar.txt").unwrap();
let mut current_dir = current_dir().unwrap();
current_dir.push("test/bar.txt");
assert_eq!(f.as_path(), current_dir.as_path());
Repairable Error

If the destination path already exists, return an error that can be recovered

Example
use fdir::{FileInfo, FileAttr};
FileInfo::create("test/foo.txt").unwrap();
let mut f = FileInfo::create("foo.txt").unwrap();

let res = f.move_new("test/foo.txt");
assert!(res.is_err());
let res = f.move_new("test/foo.txt").or_else(|e| e.try_recover());
assert!(res.is_ok())

Provided Methods§

source

fn file_name(&self) -> Option<&OsStr>

Returns None if the path is root directory

source

fn metadata(&self) -> Result<Metadata>

source

fn parent(&self) -> Option<DirectoryInfo>

Return None if the path is a root directory

source

fn permissions(&self) -> Result<Permissions>

source

fn set_permissions(&self, perm: Permissions) -> Result<()>

source

fn read_only(&self) -> Result<bool>

source

fn set_readonly(&self, readonly: bool) -> Result<()>

source

fn delete(self) -> Result<()>

source

fn copy_to<P: AsRef<Path>>(&self, path: P) -> RecoverResult<'_>

Copy a file or directory to a new directory

Examples
use fdir::{FileInfo, FileAttr};

let f = FileInfo::create("foo.txt").unwrap();
f.copy_to("test").unwrap();
assert!(FileInfo::open("test/foo.txt").is_ok())
Repairable Error

If the destination path already exists, return an error that can be recovered

Example
use fdir::{FileInfo, FileAttr};

FileInfo::create("test/foo.txt").unwrap();
let f = FileInfo::create("foo.txt").unwrap();
let res = f.copy_to("test");
assert!(res.is_err());
let res = f.copy_to("test").or_else(|e| e.try_recover());
assert!(res.is_ok())
source

fn move_to<P: AsRef<Path>>(&mut self, path: P) -> RecoverResult<'_>

Move a file or directory to a new directory

Examples
use std::env::current_dir;
use fdir::{FileInfo, FileAttr};
let mut f = FileInfo::create("foo.txt").unwrap();
f.move_to("test").unwrap();
let mut current_dir = current_dir().unwrap();
current_dir.push("test/foo.txt");
assert_eq!(f.as_path(), current_dir.as_path());
Repairable Error

If the destination path already exists, return an error that can be recovered

Example
use fdir::{FileInfo, FileAttr};
FileInfo::create("test/foo.txt").unwrap();
let mut f = FileInfo::create("foo.txt").unwrap();

let res = f.move_to("test");
assert!(res.is_err());
let res = f.move_to("test").or_else(|e| e.try_recover());
assert!(res.is_ok())

Object Safety§

This trait is not object safe.

Implementors§