Trait std::os::unix::fs::MetadataExt

1.1.0 · source ·
pub trait MetadataExt {
Show 16 methods // Required methods fn dev(&self) -> u64; fn ino(&self) -> u64; fn mode(&self) -> u32; fn nlink(&self) -> u64; fn uid(&self) -> u32; fn gid(&self) -> u32; fn rdev(&self) -> u64; fn size(&self) -> u64; fn atime(&self) -> i64; fn atime_nsec(&self) -> i64; fn mtime(&self) -> i64; fn mtime_nsec(&self) -> i64; fn ctime(&self) -> i64; fn ctime_nsec(&self) -> i64; fn blksize(&self) -> u64; fn blocks(&self) -> u64;
}
Available on Unix only.
Expand description

特定于 Unix 的 fs::Metadata 扩展。

Required Methods§

source

fn dev(&self) -> u64

返回包含文件的设备的 ID。

Examples
use std::io;
use std::fs;
use std::os::unix::fs::MetadataExt;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let dev_id = meta.dev();
    Ok(())
}
Run
source

fn ino(&self) -> u64

返回索引节点号。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let inode = meta.ino();
    Ok(())
}
Run
source

fn mode(&self) -> u32

返回应用于此文件的权限。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let mode = meta.mode();
    let user_has_write_access      = mode & 0o200;
    let user_has_read_write_access = mode & 0o600;
    let group_has_read_access      = mode & 0o040;
    let others_have_exec_access    = mode & 0o001;
    Ok(())
}
Run

返回指向该文件的硬链接数。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let nb_hard_links = meta.nlink();
    Ok(())
}
Run
source

fn uid(&self) -> u32

返回此文件所有者的用户标识。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let user_id = meta.uid();
    Ok(())
}
Run
source

fn gid(&self) -> u32

返回此文件所有者的组 ID。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let group_id = meta.gid();
    Ok(())
}
Run
source

fn rdev(&self) -> u64

返回此文件的设备 ID (如果是特殊文件)。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let device_id = meta.rdev();
    Ok(())
}
Run
source

fn size(&self) -> u64

返回此文件的总大小 (以字节为单位)。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let file_size = meta.size();
    Ok(())
}
Run
source

fn atime(&self) -> i64

返回文件的最后访问时间,以自 Unix 纪元以来的秒数为单位。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let last_access_time = meta.atime();
    Ok(())
}
Run
source

fn atime_nsec(&self) -> i64

返回文件的最后访问时间,自 atime 起以纳秒为单位。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let nano_last_access_time = meta.atime_nsec();
    Ok(())
}
Run
source

fn mtime(&self) -> i64

返回文件的最后修改时间,以自 Unix 纪元以来的秒数为单位。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let last_modification_time = meta.mtime();
    Ok(())
}
Run
source

fn mtime_nsec(&self) -> i64

返回文件的最后修改时间,自 mtime 起以纳秒为单位。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let nano_last_modification_time = meta.mtime_nsec();
    Ok(())
}
Run
source

fn ctime(&self) -> i64

返回文件的最后状态更改时间,以自 Unix 纪元以来的秒数为单位。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let last_status_change_time = meta.ctime();
    Ok(())
}
Run
source

fn ctime_nsec(&self) -> i64

返回文件的最后状态更改时间,自 ctime 起以纳秒为单位。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let nano_last_status_change_time = meta.ctime_nsec();
    Ok(())
}
Run
source

fn blksize(&self) -> u64

返回文件系统 I/O 的块大小。

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let block_size = meta.blksize();
    Ok(())
}
Run
source

fn blocks(&self) -> u64

返回以 512 字节为单位分配给文件的块数。

请注意,当文件有 holes 时,这个值可能小于 st_size / 512

Examples
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;

fn main() -> io::Result<()> {
    let meta = fs::metadata("some_file")?;
    let blocks = meta.blocks();
    Ok(())
}
Run

Implementors§