Enum std::path::Component1.0.0[−][src]

pub enum Component<'a> {
    Prefix(PrefixComponent<'a>),
    RootDir,
    CurDir,
    ParentDir,
    Normal(&'a OsStr),
}
Expand description

路径的单个组成部分。

Component 大致对应于路径分隔符 (/ 或 \) 之间的子字符串。

该 enum 是通过迭代 Components 来创建的,而 Components 又是通过 Path 上的 components 方法创建的。

Examples

use std::path::{Component, Path};

let path = Path::new("/tmp/foo/bar.txt");
let components = path.components().collect::<Vec<_>>();
assert_eq!(&components, &[
    Component::RootDir,
    Component::Normal("tmp".as_ref()),
    Component::Normal("foo".as_ref()),
    Component::Normal("bar.txt".as_ref()),
]);
Run

Variants

Prefix(PrefixComponent<'a>)

Windows 路径前缀,例如 C: 或 \\server\share。

前缀类型种类繁多,有关更多信息,请参见 Prefix 的文档。

在 Unix 上不会发生。

RootDir

根目录组件出现在任何前缀之后和其他任何内容之前。

它代表一个分隔符,它指定路径从根开始。

CurDir

对当前目录的引用,即 ..

ParentDir

对父目录的引用,即 ...

Normal(&'a OsStr)

正常组件,例如 a/b 中的 a 和 b。

这个成员是最常见的一个,它代表对文件或目录的引用。

Implementations

提取基础的 OsStr 切片。

Examples

use std::path::Path;

let path = Path::new("./tmp/foo/bar.txt");
let components: Vec<_> = path.components().map(|comp| comp.as_os_str()).collect();
assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]);
Run

Trait Implementations

执行转换。

执行转换。

返回值的副本。 Read more

从 source 执行复制分配。 Read more

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

将该值输入给定的 Hasher。 Read more

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

此方法返回 self 和 other 之间的 Ordering。 Read more

比较并返回两个值中的最大值。 Read more

比较并返回两个值中的最小值。 Read more

将值限制为一定的时间间隔。 Read more

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

此方法测试 !=。

如果存在,则此方法返回 self 和 other 值之间的顺序。 Read more

此方法测试的内容少于 (对于 self 和 other),并且由 < 操作员使用。 Read more

此方法测试小于或等于 (对于 self 和 other),并且由 <= 运算符使用。 Read more

此方法测试大于 (对于 self 和 other),并且由 > 操作员使用。 Read more

此方法测试是否大于或等于 (对于 self 和 other),并且由 >= 运算符使用。 Read more

Auto Trait Implementations

Blanket Implementations

获取 self 的 TypeId。 Read more

从拥有的值中一成不变地借用。 Read more

从拥有的值中借用。 Read more

执行转换。

执行转换。

获得所有权后的结果类型。

通常通过克隆从借用数据中创建拥有的数据。 Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

使用借来的数据来替换拥有的数据,通常是通过克隆。 Read more

发生转换错误时返回的类型。

执行转换。

发生转换错误时返回的类型。

执行转换。