Trait Metadata

Source
pub trait Metadata: Clone + Debug {
    type Permissions: Permissions;
    type FileType: FileType;

    // Required methods
    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>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

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.

Required Associated Types§

Source

type Permissions: Permissions

The Permissions type in the same module implementing this trait.

Source

type FileType: FileType

The FileType type in the same module implementing this trait.

Required Methods§

Source

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

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

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

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

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

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

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

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§

Source

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§