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 GenFS
s metadata
or symlink_metadata
methods and
represents known metadata information about a file at the instant this trait is instantiated.
Required Associated Types§
Sourcetype Permissions: Permissions
type Permissions: Permissions
The Permissions
type in the same module implementing this trait.
Required Methods§
Sourcefn file_type(&self) -> Self::FileType
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());
Sourcefn is_dir(&self) -> bool
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());
Sourcefn is_file(&self) -> bool
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());
Sourcefn len(&self) -> u64
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());
Sourcefn permissions(&self) -> Self::Permissions
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());
Sourcefn modified(&self) -> Result<SystemTime>
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");
}
Sourcefn accessed(&self) -> Result<SystemTime>
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");
}
Sourcefn created(&self) -> Result<SystemTime>
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§
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.