Struct Metadata

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

Metadata information about a file.

This structure is returned from the metadata or symlink_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 is_dir(&self) -> bool

Returns true if this metadata is for a directory.

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("path/to/dir").await?;

    println!("{:?}", metadata.is_dir());
    Ok(())
}
Source

pub fn is_file(&self) -> bool

Returns true if this metadata is for a regular file.

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt").await?;

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

Returns true if this metadata is for a symbolic link.

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt").await?;

    println!("{:?}", metadata.is_symlink());
    Ok(())
}
Source

pub fn len(&self) -> u64

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

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt").await?;

    println!("{:?}", metadata.len());
    Ok(())
}
Source

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

Returns the last modification time listed in this metadata.

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
   let metadata = fs::metadata("foo.txt").await?;

   println!("{:?}", metadata.modified());
   Ok(())
}
Source

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

Returns the last access time listed in this metadata.

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt").await?;

    println!("{:?}", metadata.accessed());
    Ok(())
}
Source

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

Returns the creation time listed in this metadata.

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt").await?;

    println!("{:?}", metadata.created());
    Ok(())
}
Source

pub fn permissions(&self) -> Permissions

Returns the permissions of the file this metadata is for.

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt").await?;

    println!("{:?}", metadata.permissions());
    Ok(())
}
Source

pub fn file_type(&self) -> FileType

Returns the file type for this metadata.

§Examples
use monoio::fs;

#[monoio::main]
async fn main() -> std::io::Result<()> {
    let metadata = fs::metadata("foo.txt").await?;

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

Trait Implementations§

Source§

impl Debug for Metadata

Source§

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

Formats the value using the given formatter. Read more
Source§

impl MetadataExt for Metadata

longarch64 need the into convert.

Source§

fn dev(&self) -> u64

Returns the ID of the device containing the file. Read more
Source§

fn ino(&self) -> u64

Returns the inode number. Read more
Source§

fn mode(&self) -> u32

Returns the rights applied to this file. Read more
Source§

fn uid(&self) -> u32

Returns the user ID of the owner of this file. Read more
Source§

fn gid(&self) -> u32

Returns the group ID of the owner of this file. Read more
Source§

fn rdev(&self) -> u64

Returns the device ID of this file (if it is a special one). Read more
Source§

fn size(&self) -> u64

Returns the total size of this file in bytes. Read more
Source§

fn atime(&self) -> i64

Returns the last access time of the file, in seconds since Unix Epoch. Read more
Source§

fn atime_nsec(&self) -> i64

Returns the last access time of the file, in nanoseconds since atime. Read more
Source§

fn mtime(&self) -> i64

Returns the last modification time of the file, in seconds since Unix Epoch. Read more
Source§

fn mtime_nsec(&self) -> i64

Returns the last modification time of the file, in nanoseconds since mtime. Read more
Source§

fn ctime(&self) -> i64

Returns the last status change time of the file, in seconds since Unix Epoch. Read more
Source§

fn ctime_nsec(&self) -> i64

Returns the last status change time of the file, in nanoseconds since ctime. Read more
Source§

fn blksize(&self) -> u64

Returns the block size for filesystem I/O. Read more
Source§

fn blocks(&self) -> u64

Returns the number of blocks allocated to the file, in 512-byte units. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.