gpt4 book ai didi

windows - PathBuf::starts_with 不适用于反斜杠

转载 作者:行者123 更新时间:2023-12-03 11:39:34 24 4
gpt4 key购买 nike

use std::path::PathBuf;

fn main() {
let p = PathBuf::from(r"\\?\C:\test");
println!("{}", p.starts_with(r"\\?\"));
println!("{}", p.starts_with("r\\"));
println!("{}", p.to_string_lossy().starts_with(r"\\?\"));
}

结果:
false
false
true

当我尝试使用 / 时而不是 \然后它按预期工作。为什么不 starts_with使用反斜杠?

最佳答案

根据 rust-lang.org 论坛上的回复:PathBuf API 为路径自省(introspection) API 跳过它,这样 \\?\C:\path行为与 C:\path 相同.
回答问题。这种行为很烦人,应该在文档中明确提及。

关于windows - PathBuf::starts_with 不适用于反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61796818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com