Allow stripping prefix on paths of all forms

This commit is contained in:
Ian Manske 2024-06-01 15:46:49 -04:00
parent 607f5fc947
commit 66580519ae

View File

@ -75,6 +75,16 @@ impl<Form: PathForm> Path<Form> {
self.inner.file_name()
}
#[inline]
pub fn strip_prefix<F: PathForm>(
&self,
base: impl AsRef<Path<F>>,
) -> Result<&RelativePath, StripPrefixError> {
self.inner
.strip_prefix(&base.as_ref().inner)
.map(RelativePath::new_unchecked)
}
#[inline]
pub fn starts_with<F: PathForm>(&self, base: impl AsRef<Path<F>>) -> bool {
self.inner.starts_with(&base.as_ref().inner)
@ -162,16 +172,6 @@ impl Path {
.then_some(RelativePath::new_unchecked(&self.inner))
.ok_or(AbsolutePath::new_unchecked(&self.inner))
}
#[inline]
pub fn strip_prefix<Form: PathForm>(
&self,
base: impl AsRef<Path<Form>>,
) -> Result<&RelativePath, StripPrefixError> {
self.inner
.strip_prefix(&base.as_ref().inner)
.map(RelativePath::new_unchecked)
}
}
impl<Form: PathJoin> Path<Form> {