为什么这段代码返回 false
use std::path::Path;
fn main() {
println!(
"Ends with? {:?}",
&Path::new("some.file.d.ts").ends_with("ts")
);
}
Run Code Online (Sandbox Code Playgroud)
文档对此有明确说明:
判断是否
child是 的后缀self。只考虑整个路径组件来匹配
像这样的扩展ts不是整个路径组件。
所以,它是真的的情况会是这样的:
use std::path::Path;
fn main() {
println!(
"Ends with? {:?}",
&Path::new("/path/to/some.file.d.ts").ends_with("some.file.d.ts")
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
552 次 |
| 最近记录: |