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 GenFSs metadata or symlink_metadata methods and represents known metadata information about a file at the instant this trait is instantiated.

Associated Types

The Permissions type in the same module implementing this trait.

The FileType type in the same module implementing this trait.

Required Methods

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());

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());

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());

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());

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());

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");
}

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");
}

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

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());

Implementors