Sync computers
This commit is contained in:
33
crates/bffs/src/path.rs
Normal file
33
crates/bffs/src/path.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
pub struct Path<'a> {
|
||||
inner: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for Path<'a> {
|
||||
fn from(value: &'a str) -> Self {
|
||||
Self { inner: value }
|
||||
}
|
||||
}
|
||||
impl<'a> AsRef<str> for Path<'a> {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Path<'a> {
|
||||
pub fn split_path(&self) -> (&'a str, Option<Path<'a>>) {
|
||||
if let Some((start, end)) = self.inner.split_once("/") {
|
||||
(start, Some(end.into()))
|
||||
} else {
|
||||
(self.inner, None)
|
||||
}
|
||||
}
|
||||
pub fn as_str(&self) -> &'a str {
|
||||
self.inner
|
||||
}
|
||||
pub fn is_absolute(&self) -> bool {
|
||||
self.inner.starts_with("/")
|
||||
}
|
||||
pub fn is_relative(&self) -> bool {
|
||||
!self.is_absolute()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user