-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Make signature of Path::strip_prefix accept non-references #48989
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,10 +297,9 @@ pub const MAIN_SEPARATOR: char = ::sys::path::MAIN_SEP; | |
// Iterate through `iter` while it matches `prefix`; return `None` if `prefix` | ||
// is not a prefix of `iter`, otherwise return `Some(iter_after_prefix)` giving | ||
// `iter` after having exhausted `prefix`. | ||
fn iter_after<A, I, J>(mut iter: I, mut prefix: J) -> Option<I> | ||
where I: Iterator<Item = A> + Clone, | ||
J: Iterator<Item = A>, | ||
A: PartialEq | ||
fn iter_after<'a, 'b, I, J>(mut iter: I, mut prefix: J) -> Option<I> | ||
where I: Iterator<Item = Component<'a>> + Clone, | ||
J: Iterator<Item = Component<'b>>, | ||
{ | ||
loop { | ||
let mut iter_next = iter.clone(); | ||
|
@@ -1865,7 +1864,7 @@ impl Path { | |
/// # Examples | ||
/// | ||
/// ``` | ||
/// use std::path::Path; | ||
/// use std::path::{Path, PathBuf}; | ||
/// | ||
/// let path = Path::new("/test/haha/foo.txt"); | ||
/// | ||
|
@@ -1876,16 +1875,19 @@ impl Path { | |
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new(""))); | ||
/// assert_eq!(path.strip_prefix("test").is_ok(), false); | ||
/// assert_eq!(path.strip_prefix("/haha").is_ok(), false); | ||
/// | ||
/// let prefix = PathBuf::from("/test/"); | ||
/// assert_eq!(path.strip_prefix(prefix), Ok(Path::new("haha/foo.txt"))); | ||
/// ``` | ||
#[stable(since = "1.7.0", feature = "path_strip_prefix")] | ||
pub fn strip_prefix<'a, P: ?Sized>(&'a self, base: &'a P) | ||
-> Result<&'a Path, StripPrefixError> | ||
pub fn strip_prefix<'a, P>(&'a self, base: P) | ||
-> Result<&'a Path, StripPrefixError> | ||
where P: AsRef<Path> | ||
{ | ||
self._strip_prefix(base.as_ref()) | ||
} | ||
|
||
fn _strip_prefix<'a>(&'a self, base: &'a Path) | ||
fn _strip_prefix<'a>(&'a self, base: &Path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I believe |
||
-> Result<&'a Path, StripPrefixError> { | ||
iter_after(self.components(), base.components()) | ||
.map(|c| c.as_path()) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 believe the
'a
lifetime can now be elided.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.
Oops, thanks for catching this!