internal: Remove AbsPathBuf::TryFrom impl that checks too many things at once

This commit is contained in:
Lukas Wirth 2024-08-02 11:08:19 +02:00
parent 670a5ab4a9
commit 758ad25229
15 changed files with 90 additions and 95 deletions

View file

@ -1,4 +1,4 @@
//! Thin wrappers around `std::path`/`camino::path`, distinguishing between absolute and
//! Thin wrappers around [`camino::path`], distinguishing between absolute and
//! relative paths.
use std::{
@ -8,9 +8,9 @@ use std::{
path::{Path, PathBuf},
};
pub use camino::*;
pub use camino::{Utf8Component, Utf8Components, Utf8Path, Utf8PathBuf, Utf8Prefix};
/// Wrapper around an absolute [`Utf8PathBuf`].
/// A [`Utf8PathBuf`] that is guaranteed to be absolute.
#[derive(Debug, Clone, Ord, PartialOrd, Eq, Hash)]
pub struct AbsPathBuf(Utf8PathBuf);
@ -73,16 +73,6 @@ impl TryFrom<Utf8PathBuf> for AbsPathBuf {
}
}
impl TryFrom<PathBuf> for AbsPathBuf {
type Error = PathBuf;
fn try_from(path_buf: PathBuf) -> Result<AbsPathBuf, PathBuf> {
if !path_buf.is_absolute() {
return Err(path_buf);
}
Ok(AbsPathBuf(Utf8PathBuf::from_path_buf(path_buf)?))
}
}
impl TryFrom<&str> for AbsPathBuf {
type Error = Utf8PathBuf;
fn try_from(path: &str) -> Result<AbsPathBuf, Utf8PathBuf> {