Struct ndless::fs::Metadata

source ·
pub struct Metadata(/* private fields */);
Expand description

Metadata information about a file.

This structure is returned from the metadata function or method and represents known metadata about a file such as its permissions, size, modification times, etc.

Implementations§

source§

impl Metadata

source

pub fn file_type(&self) -> FileType

Returns the file type for this metadata.

§Examples
fn main() -> std::io::Result<()> {
    use std::fs;

    let metadata = fs::metadata("foo.txt")?;

    println!("{:?}", metadata.file_type());
    Ok(())
}
source

pub fn is_dir(&self) -> bool

Returns true if this metadata is for a directory. The result is mutually exclusive to the result of is_file.

§Examples
fn main() -> std::io::Result<()> {
    use std::fs;

    let metadata = fs::metadata("foo.txt")?;

    assert!(!metadata.is_dir());
    Ok(())
}
source

pub fn is_file(&self) -> bool

Returns true if this metadata is for a regular file. The result is mutually exclusive to the result of is_dir.

§Examples
use std::fs;

fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt")?;

    assert!(metadata.is_file());
    Ok(())
}
source

pub fn len(&self) -> u64

Returns the size of the file, in bytes, this metadata is for.

§Examples
use std::fs;

fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt")?;

    assert_eq!(0, metadata.len());
    Ok(())
}
source

pub fn permissions(&self) -> Permissions

Returns the permissions of the file this metadata is for.

§Examples
use std::fs;

fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt")?;

    assert!(!metadata.permissions().readonly());
    Ok(())
}
source

pub fn modified(&self) -> Result<SystemTime>

Returns the last modification time listed in this metadata.

The returned value corresponds to the mtime field of stat on Unix platforms and the ftLastWriteTime field on Windows platforms.

§Errors

This field may not be available on all platforms, and will return an Err on platforms where it is not available.

§Examples
use std::fs;

fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt")?;

    if let Ok(time) = metadata.modified() {
        println!("{:?}", time);
    } else {
        println!("Not supported on this platform");
    }
    Ok(())
}
source

pub fn accessed(&self) -> Result<SystemTime>

Returns the last access time of this metadata.

The returned value corresponds to the atime field of stat on Unix platforms and the ftLastAccessTime field on Windows platforms.

Note that not all platforms will keep this field update in a file’s metadata, for example Windows has an option to disable updating this time when files are accessed and Linux similarly has noatime.

§Errors

This field may not be available on all platforms, and will return an Err on platforms where it is not available.

§Examples
use std::fs;

fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt")?;

    if let Ok(time) = metadata.accessed() {
        println!("{:?}", time);
    } else {
        println!("Not supported on this platform");
    }
    Ok(())
}
source

pub fn created(&self) -> Result<SystemTime>

Returns the creation time listed in this metadata.

The returned value corresponds to the birthtime field of stat on Unix platforms and the ftCreationTime field on Windows platforms.

§Errors

This field may not be available on all platforms, and will return an Err on platforms where it is not available.

§Examples
use std::fs;

fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt")?;

    if let Ok(time) = metadata.created() {
        println!("{:?}", time);
    } else {
        println!("Not supported on this platform");
    }
    Ok(())
}

Trait Implementations§

source§

impl Clone for Metadata

source§

fn clone(&self) -> Metadata

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Metadata

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.