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

pub enum Prefix<'a> {
    Verbatim(&'a OsStr),
    VerbatimUNC(&'a OsStr, &'a OsStr),
    VerbatimDisk(u8),
    DeviceNS(&'a OsStr),
    UNC(&'a OsStr, &'a OsStr),
    Disk(u8),
}
Expand description

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

Windows 使用各种路径前缀样式,包括引用来驱动卷 (例如 C:),网络共享文件夹 (例如 \\server\share) 以及其他。 另外,某些路径前缀是 “verbatim” (即以 \\?\ 前缀),在这种情况下,不 将 / 视为分隔符,并且基本上不执行规范化。

Examples

use std::path::{Component, Path, Prefix};
use std::path::Prefix::*;
use std::ffi::OsStr;

fn get_path_prefix(s: &str) -> Prefix {
    let path = Path::new(s);
    match path.components().next().unwrap() {
        Component::Prefix(prefix_component) => prefix_component.kind(),
        _ => panic!(),
    }
}

assert_eq!(Verbatim(OsStr::new("pictures")),
           get_path_prefix(r"\\?\pictures\kittens"));
assert_eq!(VerbatimUNC(OsStr::new("server"), OsStr::new("share")),
           get_path_prefix(r"\\?\UNC\server\share"));
assert_eq!(VerbatimDisk(b'C'), get_path_prefix(r"\\?\c:\"));
assert_eq!(DeviceNS(OsStr::new("BrainInterface")),
           get_path_prefix(r"\\.\BrainInterface"));
assert_eq!(UNC(OsStr::new("server"), OsStr::new("share")),
           get_path_prefix(r"\\server\share"));
assert_eq!(Disk(b'C'), get_path_prefix(r"C:\Users\Rust\Pictures\Ferris"));
Run

Variants

Verbatim(&'a OsStr)

逐字前缀,例如 \\?\cat_pics.

逐字前缀由 \\?\ 组成,紧随其后是给定的组件。

VerbatimUNC(&'a OsStr, &'a OsStr)

使用 Windows 的 U niform N aming C onvention 的逐字前缀,例如, \\?\UNC\server\share.

Verbatim UNC 前缀由 \\?\UNC\ 组成,其后紧跟服务器的主机名和共享名。

VerbatimDisk(u8)

逐字磁盘前缀,例如, \\?\C:.

逐字磁盘前缀由 \\?\ 紧随其后的驱动器号和 : 组成。

DeviceNS(&'a OsStr)

设备名称空间前缀,例如 \\.\COM42.

设备名称空间前缀由 \\.\ 紧随其后的设备名称组成。

UNC(&'a OsStr, &'a OsStr)

使用 Windows 的 U niform N aming C onvention 的前缀,例如 \\server\share.

UNC 前缀由服务器的主机名和共享名组成。

Disk(u8)

给定磁盘驱动器的前缀 C:。

Implementations

确定前缀是否为逐字形式,即以 \\?\ 开头。

Examples

use std::path::Prefix::*;
use std::ffi::OsStr;

assert!(Verbatim(OsStr::new("pictures")).is_verbatim());
assert!(VerbatimUNC(OsStr::new("server"), OsStr::new("share")).is_verbatim());
assert!(VerbatimDisk(b'C').is_verbatim());
assert!(!DeviceNS(OsStr::new("BrainInterface")).is_verbatim());
assert!(!UNC(OsStr::new("server"), OsStr::new("share")).is_verbatim());
assert!(!Disk(b'C').is_verbatim());
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

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

执行转换。

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

执行转换。