-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Docs: add corner cases of Path::file_name() #88044
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon. Please see the contribution instructions for more information. |
53fd888
to
6b4cd82
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.
Maybe this isbbetter (remove quotes in favor of only markdown code blocks)?
@jfrimmel I do think it looks weird: "Terminates in ..." looks like 3 dots, instead of 2. I will also add "(double dots)" to the side of it, to see if it helps. |
6b4cd82
to
bbca714
Compare
/// - Is empty. | ||
/// - Terminates in `..` (double dots). | ||
/// - Is root (e.g. `/`, `/.`, `/././.`). | ||
/// - Only contains current directory (e.g. `.`, `././.`). |
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 think this is missing the Prefix variant of Component -- maybe it is more useful to say "returns None if the last component of the path is not Normal" and link to https://doc.rust-lang.org/nightly/std/path/enum.Component.html?
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.
That's a great idea, however, here is the documentation of Component:
It does not explain that running components on "a/." gives Component::Normal("a")
instead of Normal("a")
AND CurrrentDirectory
, plus I think people are expecting "asd/.".file_name() to return ".", so, maybe this should be explained somewhere?
Maybe I could add examples to the docs of Component
itself to show what iterating on Path::new("/a/b/c")
retrieves, then we could also cover this corner cases.
However, there is already something like this at https://doc.rust-lang.org/nightly/std/path/struct.Path.html#method.components.
use std::path::{Path, Component};
use std::ffi::OsStr;
let mut components = Path::new("/tmp/foo.txt").components();
assert_eq!(components.next(), Some(Component::RootDir));
assert_eq!(components.next(), Some(Component::Normal(OsStr::new("tmp"))));
assert_eq!(components.next(), Some(Component::Normal(OsStr::new("foo.txt"))));
assert_eq!(components.next(), None)
So, maybe I should add more examples to path::components
instead? Or add some explanation in the Component
page itself.
Waiting for some feedback on these thoughts.
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 think adding more docs to Component makes sense, since it's a dedicated page for this. We can point there from file_name() and potentially components() as well.
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.
Nice, I agree! I've been getting very busy this days, so I might need to delay this PR just a couple weeks, but thanks for the review.
@marcospb19 any updates on this? |
@Mark-Simulacrum @Dylan-DPC sorry for the huge delay on this, I'm struggling with managing my personal time. Was not able to finish this yet. If someone want to open a PR with it finished, I'd be glad, you might want to close mine. (Or commit on my branch, for some repo member). |
@marcospb19 that's totally fine and understandable. I'll close this for now, thanks for taking the time to contribute to rust. |
Documenting corner cases where
Path::file_name()
returnsNone
, and adding examples.