Skip to content
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

Merged
merged 6 commits into from
Nov 15, 2023
Merged

Add path manipulation utils #47

merged 6 commits into from
Nov 15, 2023

Conversation

sosthene-nitrokey
Copy link
Contributor

No description provided.

Copy link
Member

@robin-nitrokey robin-nitrokey left a 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Some((_, "\x00"))?

Copy link
Contributor Author

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),
Copy link
Member

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.

Copy link
Contributor Author

@sosthene-nitrokey sosthene-nitrokey Nov 14, 2023

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@robin-nitrokey robin-nitrokey left a 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.

@sosthene-nitrokey
Copy link
Contributor Author

sosthene-nitrokey commented Nov 15, 2023

There had been a couple of addition since the first approval.

@sosthene-nitrokey sosthene-nitrokey merged commit 9c2d48d into main Nov 15, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants