Skip to content

Struct std::fs::FileType

表示文件类型的结构体,每个文件类型都有访问器。 通过 Metadata::file_type 方法返回。

1.Implementations

impl FileType

is_dir

判断此文件类型是否为目录(文件夹)

rust
pub fn is_dir(&self) -> bool

返回值:根据文件类型是否为目录,返回bool值

is_file

根据文件类型是否为文件

rust
pub fn is_file(&self) -> bool

返回值:根据文件类型是否为文件,返回bool值

TIP

当目标只是读取 (或写入) 源时,可以读取 (或写入) 最可靠的测试源方法是打开它。 例如,仅使用 is_file 才能中断类似 Unix 的系统上的工作流,例如 diff <( prog_a )。 有关更多信息,请参见 File::openOpenOptions::open

判断此文件类型是否为软链接

rust
pub fn is_symlink(&self) -> bool

返回值:根据文件类型是否为软链接,返回bool值

TIP

需要使用 fs::symlink_metadata 函数而不是 fs::metadata 函数来检索底层 Metadata 结构。 fs::metadata 函数遵循符号链接,因此 is_symlink 将始终为目标文件返回 false

2.Trait Implementations

impl Clone for FileType

clone

返回值的副本。

rust
fn clone(&self) -> FileType

1.0.0 ·

clone_from

从 执行复制分配。

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

impl Debug for FileType

fmt

使用给定的格式化程序格式化该值。

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

impl FileTypeExt for FileType

TIP

仅在windows可用

如果此文件类型是也是目录的符号链接,则返回 true。

rust
fn is_symlink_dir(&self) -> bool

如果此文件类型是也是文件的符号链接,则返回 true。

rust
fn is_symlink_file(&self) -> bool

impl FileTypeExt for FileType

TIP

仅在WASI可用

is_block_device

如果此文件类型是块设备,则返回 true。

rust
fn is_block_device(&self) -> bool

is_char_device

如果此文件类型是字符设备,则返回 true。

rust
fn is_char_device(&self) -> bool

is_socket_dgram

如果此文件类型是套接字数据报,则返回 true。

rust
fn is_socket_dgram(&self) -> bool

is_socket_stream

如果此文件类型是套接字流,则返回 true。

rust
fn is_socket_stream(&self) -> bool

is_socket

如果此文件类型是任何类型的套接字,则返回 true。

rust
fn is_socket(&self) -> bool

impl FileTypeExt for FileType

TIP

仅在Unix可用

is_block_device

如果此文件类型是块设备,则返回 true。

rust
fn is_block_device(&self) -> bool

is_char_device

如果此文件类型是 char 设备,则返回 true。

rust
fn is_char_device(&self) -> bool

is_fifo

如果此文件类型为 fifo,则返回 true。

rust
fn is_fifo(&self) -> bool

is_socket

如果此文件类型是套接字,则返回 true。

rust
fn is_socket(&self) -> bool

impl Hash for FileType

hash

将该值输入给定的 Hasher。

rust
fn hash<__H: Hasher>(&self, state: &mut __H)

hash_slice

将这种类型的切片送入给定的 Hasher 中。

rust
fn hash_slice<H>(data: &[Self], state: &mut H)
where
  H: Hasher,
  Self: Sized,

impl PartialEq<FileType> for FileType

eq

此方法测试 self 和 other 值是否相等,并由 == 使用。

rust
fn eq(&self, other: &FileType) -> bool

ne

此方法测试 !=。 默认实现几乎总是足够的,并且不应在没有充分理由的情况下被覆盖。

rust
fn ne(&self, other: &Rhs) -> bool

impl Copy for FileType

impl Eq for FileType

impl StructuralEq for FileType

impl StructuralPartialEq for FileType

3.Auto Trait Implementations

impl RefUnwindSafe for FileType

impl Send for FileType

impl Sync for FileType

impl Unpin for FileType

impl UnwindSafe for FileType

4.Blanket Implementations

impl<T> Any for T

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

impl<T> Borrow<T> for T

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

impl<T> BorrowMut<T> for T

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

impl<T> From<T> for T

rust
impl<T> From<T> for T

impl<T, U> Into<U> for T

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

impl<T> ToOwned for T

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

impl<T, U> TryFrom<U> for T

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

impl<T, U> TryInto<U> for T

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

MIT Licensed