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
返回包含文件的设备的 ID。
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
返回索引节点号。
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
返回应用于此文件的权限。
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
返回指向该文件的硬链接数。
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
返回此文件所有者的用户标识。
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
返回此文件所有者的组 ID。
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
返回此文件的设备 ID (如果是特殊文件)。
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
返回此文件的总大小 (以字节为单位)。
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
返回文件的最后访问时间,以自 Unix 纪元以来的秒数为单位。
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
返回文件的最后访问时间,自 atime
起以纳秒为单位。
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
返回文件的最后修改时间,以自 Unix 纪元以来的秒数为单位。
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
返回文件的最后修改时间,自 mtime
起以纳秒为单位。
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
返回文件的最后状态更改时间,以自 Unix 纪元以来的秒数为单位。
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
返回文件的最后状态更改时间,自 ctime
起以纳秒为单位。
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
返回文件系统 I/O 的块大小。
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
返回以 512 字节为单位分配给文件的块数。
请注意,当文件有 holes 时,这个值可能小于 st_size / 512
。
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