Rust `ends_with` and `strip_prefix` behavior differences in `Path` and `str`
As I’m writing an ignore library, I’m having subtle bugs caused by Rust’s Path
behavior.
ends_with
in Path is different fromends_with
ofstr
If you try to check whether thePath
is a directory by the final character, you’ll see thatpath.ends_with("/")
returnsfalse
.Path::strip_prefix
eats also the final slash. This means if you have a directory marker at the end,/Users/emre/mydir/
and send it tostrip_prefix("/Users/emre")
, you’ll getmydir
, notmydir/
.