Sync computers

This commit is contained in:
2026-03-01 16:12:02 +01:00
parent 392af94345
commit 041e544330
7 changed files with 59 additions and 41 deletions

View File

@@ -1,33 +1,46 @@
use core::ops::Deref;
#[cfg(feature = "alloc")]
use alloc::string::String;
#[repr(transparent)]
pub struct Path<'a> {
inner: &'a str,
pub struct Path {
inner: str,
}
impl<'a> From<&'a str> for Path<'a> {
fn from(value: &'a str) -> Self {
Self { inner: value }
impl From<&str> for &Path {
fn from(value: &str) -> Self {
unsafe { &*(value as *const str as *const Path) }
}
}
impl<'a> AsRef<str> for Path<'a> {
impl AsRef<Path> for str {
fn as_ref(&self) -> &Path {
unsafe { &*(self as *const str as *const Path) }
}
}
impl AsRef<Path> for Path {
fn as_ref(&self) -> &Path {
self
}
}
impl AsRef<str> for Path {
fn as_ref(&self) -> &str {
self.inner
self.as_str()
}
}
impl<'a> Path<'a> {
pub fn split_path(&self) -> (&'a str, Option<Path<'a>>) {
impl Path {
pub fn split_path(&self) -> (&str, Option<&Path>) {
if let Some((start, end)) = self.inner.split_once("/") {
(start, Some(end.into()))
} else {
(self.inner, None)
(&self.inner, None)
}
}
pub fn as_str(&self) -> &'a str {
self.inner
pub fn as_str(&self) -> &str {
&self.inner
}
pub fn is_absolute(&self) -> bool {
self.inner.starts_with("/")
@@ -37,12 +50,16 @@ impl<'a> Path<'a> {
}
}
#[cfg(feature = "alloc")]
pub struct PathBuf {
inner: String,
}
impl<'a> Deref for PathBuf {
type Target = Path<'a>;
#[cfg(feature = "alloc")]
impl Deref for PathBuf {
type Target = Path;
fn deref(&self) -> &Self::Target {}
fn deref(&self) -> &Self::Target {
self.inner.as_str().into()
}
}