-
Notifications
You must be signed in to change notification settings - Fork 19
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
Path::is_trivial #487
Comments
Is this definition of "trivial" used anywhere else? I think it may be better to break it down into two functions that has clearer definitions
fn is_trivial(path: &Path) -> bool {
!path.has_root() && path.is_normalized_lexically()
} Questions: are these considered trivial / normalized lexically?
for this motivation the proposed function based on Path may be inappropriate when portability is considered, for instance on Unix you a path |
That will return true for both fn has_windows_legacy_prefix(path: &Path) -> bool {
!path.is_absolute() && matches!(path.components().next(), Some(Component::Prefix(_)))
} Then |
@ChrisDenton Ok :( For the first test I think what we are interested in is whether the path is "completely relative". In Python terms meaning the path has no "anchor" impl Path {
pub fn is_anchored(&self) -> bool {
matches!(self.components().next(), Some(Component::Prefix(_) | Component::RootDir)))
}
} |
I would propose a |
you still need to have the checking if you ever want to take it from user input. also, |
Yes, you'd check once and be done rather than every function dealing with paths having to act defensively (and not forget!).
If a |
We discussed this in today's @rust-lang/libs-api meeting. We all agreed that we want a method with this behavior. We spent a while attempting to bikeshed naming. Rough summary of the bikeshedding:
We also talked about whether this should allow things like Ultimately, something like Linux's We didn't come to any consensus, and we'd welcome input. |
Another possibility that came to mind: |
Proposal
Problem statement
The standard library currently contains functions that distinguish between relative and absolute paths, but sometimes it is desirable to only accept an even more restricted subset of paths.
Motivating examples or use cases
Programs that do filesystem traversal within an inner loop may want to reuse a buffer to store paths in, but this can lead to logic errors if those paths are complex, such as
C:something
or../foo
.This could also be useful for programs that want to validate a configuration file or path-like argument, for example git would want to reject branch names containing
..
, or that would be stored on another drive.Solution sketch
Alternatives
has_drive_letter
andis_verbatim
.Links and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: