Fix Vfs::add_path: Use to_string_lossy

instead of `to_str` to be compatible with the implementation in
`cargo_toml`:

https://docs.rs/cargo_toml/0.11.5/src/cargo_toml/afs.rs.html#24

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-12 19:23:03 +10:00
parent b88e384f95
commit bd39ce754f
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -20,12 +20,14 @@ impl Vfs {
// Since path has parent, it must have a filename // Since path has parent, it must have a filename
let filename = path.file_name().unwrap(); let filename = path.file_name().unwrap();
if let Some(filename) = filename.to_str() { // `cargo_toml`'s implementation does the same thing.
// https://docs.rs/cargo_toml/0.11.5/src/cargo_toml/afs.rs.html#24
let filename = filename.to_string_lossy();
self.0 self.0
.entry(parent.into()) .entry(parent.into())
.or_insert_with(|| HashSet::with_capacity(4)) .or_insert_with(|| HashSet::with_capacity(4))
.insert(filename.into()); .insert(filename.into());
}
path = parent; path = parent;
} }