-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add path manipulation utils #47
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
src/path.rs
Outdated
pub fn file_name(&self) -> Option<&Path> { | ||
let this = self.as_str_ref_with_trailing_nul(); | ||
match this.rsplit_once('/') { | ||
Some((_, path)) if path == "\x00" => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Some((_, "\x00"))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed better.
src/path.rs
Outdated
let this = self.as_str_ref_with_trailing_nul(); | ||
match this.rsplit_once('/') { | ||
Some((_, path)) if path == "\x00" => None, | ||
None if this != "\x00" => Some(self), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Check self.inner.is_empty()
at the start of the method instead? Then this could be a map
instead. Maybe easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would that allow getting rid of the Some((_, "\x00"))
case? This case handles paths that end with a trailing slash but are not empty. We could return file.extension
for path!("/some/path/file.extension/").file_name()
but that would mean using either a PathBuf
or &str
as the return type.
I generally don't like using those, but it might be the best solution. It would match the behaviour of std.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I curse C and its trailing 0
. It's so unpractical to require copying and not having any ability to slice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would not get rid of it, but it would get rid of the None
case and an if
in a map
or a filter
plus a map
could be easier to read than the match. But that’s just a feeling. This version is fine too of course.
ddb8415
to
e6c46e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea why my approval is not displayed anymore.
There had been a couple of addition since the first approval. |
No description provided.