Sync computers
This commit is contained in:
@@ -44,31 +44,29 @@ impl<'a, T> Dir<'a, T> {
|
||||
}
|
||||
}
|
||||
impl<'a, T: ReadSeek> Dir<'a, T> {
|
||||
pub fn open_entry<'b, P: Into<Path<'b>>>(
|
||||
pub fn open_entry<P: AsRef<Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<DirEntry<'a, T>, Error<T::Error>> {
|
||||
let path = path.into();
|
||||
if path.is_absolute() {
|
||||
if path.as_ref().is_absolute() {
|
||||
return self.fs.open_entry(path);
|
||||
}
|
||||
for file in self.iter() {
|
||||
let f = file?;
|
||||
if f.name_is(path.as_str()) {
|
||||
if f.name_is(path.as_ref().as_str()) {
|
||||
return Ok(f);
|
||||
}
|
||||
}
|
||||
Err(Error::NotFound)
|
||||
}
|
||||
pub fn open_file<'b, P: Into<Path<'b>>>(
|
||||
pub fn open_file<P: AsRef<Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<File<'a, T>, Error<T::Error>> {
|
||||
let path = path.into();
|
||||
if path.is_absolute() {
|
||||
if path.as_ref().is_absolute() {
|
||||
return self.fs.open_file(path);
|
||||
}
|
||||
let (start, dirname) = path.split_path();
|
||||
let (start, dirname) = path.as_ref().split_path();
|
||||
let entry = self.open_entry(start)?;
|
||||
match dirname {
|
||||
Some(name) => {
|
||||
@@ -85,8 +83,8 @@ impl<'a, T: ReadSeek> Dir<'a, T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open_dir<'b, P: Into<Path<'b>>>(&self, path: P) -> Result<Self, Error<T::Error>> {
|
||||
let path = path.into();
|
||||
pub fn open_dir<P: AsRef<Path>>(&self, path: P) -> Result<Self, Error<T::Error>> {
|
||||
let path = path.as_ref();
|
||||
if path.is_absolute() {
|
||||
return self.fs.open_dir(path);
|
||||
}
|
||||
|
||||
@@ -136,22 +136,22 @@ impl<T> Fat32FileSystem<T> {
|
||||
}
|
||||
}
|
||||
impl<T: ReadSeek> Fat32FileSystem<T> {
|
||||
pub fn open_entry<'b, P: Into<Path<'b>>>(
|
||||
pub fn open_entry<P: AsRef<Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<DirEntry<'_, T>, Error<T::Error>> {
|
||||
let path = path.into().as_str().trim_start_matches("/");
|
||||
let path = path.as_ref().as_str().trim_start_matches("/");
|
||||
self.root_directory().open_entry(path)
|
||||
}
|
||||
pub fn open_dir<'b, P: Into<Path<'b>>>(&self, path: P) -> Result<Dir<'_, T>, Error<T::Error>> {
|
||||
let path = path.into().as_str().trim_start_matches("/");
|
||||
pub fn open_dir<P: AsRef<Path>>(&self, path: P) -> Result<Dir<'_, T>, Error<T::Error>> {
|
||||
let path = path.as_ref().as_str().trim_start_matches("/");
|
||||
self.root_directory().open_dir(path)
|
||||
}
|
||||
pub fn open_file<'b, P: Into<Path<'b>>>(
|
||||
pub fn open_file<P: AsRef<Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<File<'_, T>, Error<T::Error>> {
|
||||
let path = path.into().as_str().trim_start_matches("/");
|
||||
let path = path.as_ref().as_str().trim_start_matches("/");
|
||||
self.root_directory().open_file(path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user