Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/paths/src/lib.rs')
-rw-r--r--crates/paths/src/lib.rs20
1 files changed, 7 insertions, 13 deletions
diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs
index 885f071889..0084244161 100644
--- a/crates/paths/src/lib.rs
+++ b/crates/paths/src/lib.rs
@@ -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> {
@@ -151,6 +141,10 @@ impl AbsPathBuf {
pub fn push<P: AsRef<Utf8Path>>(&mut self, suffix: P) {
self.0.push(suffix)
}
+
+ pub fn join(&self, path: impl AsRef<Utf8Path>) -> Self {
+ Self(self.0.join(path))
+ }
}
impl fmt::Display for AbsPathBuf {