mirror of https://github.com/astral-sh/ruff
[red-knot] Simplify conversions from `std::path::Path` to `VendoredPath(Buf)` (#11988)
This commit is contained in:
parent
f846fc9e07
commit
375d2c87b2
|
|
@ -49,12 +49,8 @@ mod tests {
|
||||||
panic!("Expected {absolute_path:?} to be a child of {vendored_typeshed_dir:?}")
|
panic!("Expected {absolute_path:?} to be a child of {vendored_typeshed_dir:?}")
|
||||||
});
|
});
|
||||||
|
|
||||||
let posix_style_path = relative_path
|
let vendored_path = <&VendoredPath>::try_from(relative_path)
|
||||||
.as_os_str()
|
.unwrap_or_else(|_| panic!("Expected {relative_path:?} to be valid UTF-8"));
|
||||||
.to_str()
|
|
||||||
.unwrap_or_else(|| panic!("Expected {relative_path:?} to be a valid UTF-8 path"));
|
|
||||||
|
|
||||||
let vendored_path = VendoredPath::new(posix_style_path);
|
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
vendored_typeshed_stubs.exists(vendored_path),
|
vendored_typeshed_stubs.exists(vendored_path),
|
||||||
|
|
|
||||||
|
|
@ -93,3 +93,19 @@ impl Deref for VendoredPathBuf {
|
||||||
self.as_path()
|
self.as_path()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<&'a path::Path> for &'a VendoredPath {
|
||||||
|
type Error = camino::FromPathError;
|
||||||
|
|
||||||
|
fn try_from(value: &'a path::Path) -> Result<Self, Self::Error> {
|
||||||
|
Ok(VendoredPath::new(<&camino::Utf8Path>::try_from(value)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<path::PathBuf> for VendoredPathBuf {
|
||||||
|
type Error = camino::FromPathBufError;
|
||||||
|
|
||||||
|
fn try_from(value: path::PathBuf) -> Result<Self, Self::Error> {
|
||||||
|
Ok(VendoredPathBuf(camino::Utf8PathBuf::try_from(value)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue