Make signature of Path::strip_prefix un-bizarre
BREAKING CHANGE: This has the potential to cause regressions in type inference.
This commit is contained in:
parent
27a046e933
commit
0d0a470b89
1 changed files with 10 additions and 8 deletions
|
@ -297,10 +297,9 @@ pub const MAIN_SEPARATOR: char = ::sys::path::MAIN_SEP;
|
||||||
// Iterate through `iter` while it matches `prefix`; return `None` if `prefix`
|
// Iterate through `iter` while it matches `prefix`; return `None` if `prefix`
|
||||||
// is not a prefix of `iter`, otherwise return `Some(iter_after_prefix)` giving
|
// is not a prefix of `iter`, otherwise return `Some(iter_after_prefix)` giving
|
||||||
// `iter` after having exhausted `prefix`.
|
// `iter` after having exhausted `prefix`.
|
||||||
fn iter_after<A, I, J>(mut iter: I, mut prefix: J) -> Option<I>
|
fn iter_after<'a, 'b, I, J>(mut iter: I, mut prefix: J) -> Option<I>
|
||||||
where I: Iterator<Item = A> + Clone,
|
where I: Iterator<Item = Component<'a>> + Clone,
|
||||||
J: Iterator<Item = A>,
|
J: Iterator<Item = Component<'b>>,
|
||||||
A: PartialEq
|
|
||||||
{
|
{
|
||||||
loop {
|
loop {
|
||||||
let mut iter_next = iter.clone();
|
let mut iter_next = iter.clone();
|
||||||
|
@ -1865,7 +1864,7 @@ impl Path {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::path::Path;
|
/// use std::path::{Path, PathBuf};
|
||||||
///
|
///
|
||||||
/// let path = Path::new("/test/haha/foo.txt");
|
/// 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/haha/foo.txt/"), Ok(Path::new("")));
|
||||||
/// assert_eq!(path.strip_prefix("test").is_ok(), false);
|
/// assert_eq!(path.strip_prefix("test").is_ok(), false);
|
||||||
/// assert_eq!(path.strip_prefix("/haha").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")]
|
#[stable(since = "1.7.0", feature = "path_strip_prefix")]
|
||||||
pub fn strip_prefix<'a, P: ?Sized>(&'a self, base: &'a P)
|
pub fn strip_prefix<'a, P>(&'a self, base: P)
|
||||||
-> Result<&'a Path, StripPrefixError>
|
-> Result<&'a Path, StripPrefixError>
|
||||||
where P: AsRef<Path>
|
where P: AsRef<Path>
|
||||||
{
|
{
|
||||||
self._strip_prefix(base.as_ref())
|
self._strip_prefix(base.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _strip_prefix<'a>(&'a self, base: &'a Path)
|
fn _strip_prefix<'a>(&'a self, base: &Path)
|
||||||
-> Result<&'a Path, StripPrefixError> {
|
-> Result<&'a Path, StripPrefixError> {
|
||||||
iter_after(self.components(), base.components())
|
iter_after(self.components(), base.components())
|
||||||
.map(|c| c.as_path())
|
.map(|c| c.as_path())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue