Trait rsfs::Metadata
[−]
[src]
pub trait Metadata: Clone + Debug { type Permissions: Permissions; type FileType: FileType; fn file_type(&self) -> Self::FileType; fn is_dir(&self) -> bool; fn is_file(&self) -> bool; fn len(&self) -> u64; fn permissions(&self) -> Self::Permissions; fn modified(&self) -> Result<SystemTime>; fn accessed(&self) -> Result<SystemTime>; fn created(&self) -> Result<SystemTime>; fn is_empty(&self) -> bool { ... } }
Metadata information about a file.
This trait is returned from GenFS
s metadata
or symlink_metadata
methods and
represents known metadata information about a file at the instant this trait is instantiated.
Associated Types
type Permissions: Permissions
The Permissions
type in the same module implementing this trait.
type FileType: FileType
The FileType
type in the same module implementing this trait.
Required Methods
fn file_type(&self) -> Self::FileType
Returns the file type for this metadata.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; println!("{:?}", metadata.file_type());
fn is_dir(&self) -> bool
Returns whether this metadata is for a directory.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; assert!(!metadata.is_dir());
fn is_file(&self) -> bool
Returns whether this metadata is for a file.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; assert!(metadata.is_file());
fn len(&self) -> u64
Returns the size, in bytes, of the file this metadata is for.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; assert_eq!(0, metadata.len());
fn permissions(&self) -> Self::Permissions
Returns the permissions of the file this metadata is for.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; assert!(!metadata.permissions().readonly());
fn modified(&self) -> Result<SystemTime>
Returns the last modification time listed in this metadata.
Errors
This method will return Err
on systems where it is unavailable.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; if let Ok(time) = metadata.modified() { println!("{:?}", time); } else { println!("Not supported on this platform"); }
fn accessed(&self) -> Result<SystemTime>
Returns the last access time listed in this metadata.
Errors
This method will return Err
on systems where it is unavailable.
Note that most systems will not keep a access times up to date.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; if let Ok(time) = metadata.accessed() { println!("{:?}", time); } else { println!("Not supported on this platform"); }
fn created(&self) -> Result<SystemTime>
Returns the creation time listed in this metadata.
Errors
This method will return Err
on systems where it is unavailable.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; if let Ok(time) = metadata.created() { println!("{:?}", time); } else { println!("Not supported on this platform"); }
Provided Methods
fn is_empty(&self) -> bool
Returns whether the file is empty. This defaults to checking len() == 0
.
Examples
use rsfs::*; use rsfs::mem::FS; let fs = FS::new(); let metadata = fs.metadata("foo.txt")?; assert!(metadata.is_empty());