refactor: refine PathLike and StrandLike traits (#3340)

This commit is contained in:
三咲雅 misaki masa 2025-11-19 18:07:04 +08:00 committed by GitHub
parent 9cd742811a
commit d3ad1c0920
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
109 changed files with 1282 additions and 1492 deletions

View file

@ -8,6 +8,9 @@ description = "Yazi virtual file system"
homepage = "https://yazi-rs.github.io"
repository = "https://github.com/sxyazi/yazi"
[lints]
workspace = true
[dependencies]
yazi-config = { path = "../yazi-config", version = "25.9.15" }
yazi-fs = { path = "../yazi-fs", version = "25.9.15" }

View file

@ -3,7 +3,7 @@ use std::io;
use tokio::{select, sync::{mpsc, oneshot}};
use yazi_fs::provider::Attrs;
use yazi_macro::ok_or_not_found;
use yazi_shared::{strand::{StrandBuf, StrandBufLike, StrandLike}, url::{AsUrl, Url, UrlBuf, UrlLike}};
use yazi_shared::{strand::{StrandBuf, StrandLike}, url::{AsUrl, Url, UrlBuf, UrlLike}};
use crate::provider;
@ -91,7 +91,7 @@ fn _copy_with_progress(from: Url, to: Url, attrs: Attrs) -> mpsc::Receiver<Resul
});
tokio::spawn({
let (prog_tx, to) = (prog_tx.to_owned(), to.to_owned());
let (prog_tx, to) = (prog_tx.clone(), to.to_owned());
async move {
let mut last = 0;
let mut done = None;

View file

@ -1,5 +1,5 @@
use yazi_fs::FilesOp;
use yazi_shared::{path::PathLike, url::{UrlBuf, UrlLike}};
use yazi_shared::url::{UrlBuf, UrlLike};
use crate::maybe_exists;
@ -15,7 +15,7 @@ impl VfsFilesOp for FilesOp {
} else if maybe_exists(cwd).await {
Self::IOErr(cwd.clone(), err).emit();
} else if let Some((p, n)) = cwd.pair() {
Self::Deleting(p.into(), [n.owned()].into()).emit();
Self::Deleting(p.into(), [n.into()].into()).emit();
}
}
}

View file

@ -2,7 +2,7 @@ use std::io;
use tokio::io::{AsyncWriteExt, BufReader, BufWriter};
use yazi_fs::{cha::Cha, provider::{Attrs, Provider, local::Local}};
use yazi_shared::{path::{AsPathDyn, PathBufDyn}, url::{AsUrl, UrlBuf, UrlCow}};
use yazi_shared::{path::{AsPath, PathBufDyn}, url::{AsUrl, UrlBuf, UrlCow}};
use super::{Providers, ReadDir, RwFile};
@ -199,7 +199,7 @@ where
pub async fn symlink_dir<P, U>(original: P, link: U) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
U: AsUrl,
{
Providers::new(link.as_url()).await?.symlink_dir(original).await
@ -207,7 +207,7 @@ where
pub async fn symlink_file<P, U>(original: P, link: U) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
U: AsUrl,
{
Providers::new(link.as_url()).await?.symlink_file(original).await

View file

@ -1,7 +1,7 @@
use std::io;
use yazi_fs::{cha::Cha, provider::{Attrs, Provider}};
use yazi_shared::{path::{AsPathDyn, PathBufDyn}, url::{Url, UrlBuf, UrlCow}};
use yazi_shared::{path::{AsPath, PathBufDyn}, url::{Url, UrlBuf, UrlCow}};
#[derive(Clone)]
pub(super) enum Providers<'a> {
@ -39,7 +39,7 @@ impl<'a> Provider for Providers<'a> {
async fn copy<P>(&self, to: P, attrs: Attrs) -> io::Result<u64>
where
P: AsPathDyn,
P: AsPath,
{
match self {
Self::Local(p) => p.copy(to, attrs).await,
@ -70,7 +70,7 @@ impl<'a> Provider for Providers<'a> {
async fn hard_link<P>(&self, to: P) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
{
match self {
Self::Local(p) => p.hard_link(to).await,
@ -141,7 +141,7 @@ impl<'a> Provider for Providers<'a> {
async fn rename<P>(&self, to: P) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
{
match self {
Self::Local(p) => p.rename(to).await,
@ -151,7 +151,7 @@ impl<'a> Provider for Providers<'a> {
async fn symlink<P, F>(&self, original: P, is_dir: F) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
F: AsyncFnOnce() -> io::Result<bool>,
{
match self {
@ -162,7 +162,7 @@ impl<'a> Provider for Providers<'a> {
async fn symlink_dir<P>(&self, original: P) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
{
match self {
Self::Local(p) => p.symlink_dir(original).await,
@ -172,7 +172,7 @@ impl<'a> Provider for Providers<'a> {
async fn symlink_file<P>(&self, original: P) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
{
match self {
Self::Local(p) => p.symlink_file(original).await,

View file

@ -12,24 +12,24 @@ pub struct Gate(crate::provider::Gate);
impl From<Gate> for Flags {
fn from(Gate(g): Gate) -> Self {
let mut flags = Flags::empty();
let mut flags = Self::empty();
if g.append {
flags |= Flags::APPEND;
flags |= Self::APPEND;
}
if g.create {
flags |= Flags::CREATE;
flags |= Self::CREATE;
}
if g.create_new {
flags |= Flags::CREATE | Flags::EXCLUDE;
flags |= Self::CREATE | Self::EXCLUDE;
}
if g.read {
flags |= Flags::READ;
flags |= Self::READ;
}
if g.truncate {
flags |= Flags::TRUNCATE;
flags |= Self::TRUNCATE;
}
if g.write {
flags |= Flags::WRITE;
flags |= Self::WRITE;
}
flags
}

View file

@ -39,7 +39,7 @@ impl TryFrom<(&OsStr, &yazi_sftp::fs::Attrs)> for Cha {
let kind =
if name.as_encoded_bytes().starts_with(b".") { ChaKind::HIDDEN } else { ChaKind::empty() };
Ok(Cha(yazi_fs::cha::Cha {
Ok(Self(yazi_fs::cha::Cha {
kind,
mode: ChaMode::try_from(attrs)?.0,
len: attrs.size.unwrap_or(0),

View file

@ -4,7 +4,7 @@ use tokio::io::{AsyncWriteExt, BufReader, BufWriter};
use yazi_config::vfs::{ProviderSftp, Vfs};
use yazi_fs::provider::{DirReader, FileHolder, Provider};
use yazi_sftp::fs::{Attrs, Flags};
use yazi_shared::{path::{AsPathDyn, PathBufDyn}, pool::InternStr, strand::StrandLike, url::{Url, UrlBuf, UrlCow, UrlLike}};
use yazi_shared::{path::{AsPath, PathBufDyn}, pool::InternStr, url::{Url, UrlBuf, UrlCow, UrlLike}};
use super::Cha;
use crate::provider::sftp::Conn;
@ -69,9 +69,9 @@ impl<'a> Provider for Sftp<'a> {
async fn copy<P>(&self, to: P, attrs: yazi_fs::provider::Attrs) -> io::Result<u64>
where
P: AsPathDyn,
P: AsPath,
{
let to = to.as_path_dyn().as_os()?;
let to = to.as_path().as_os()?;
let attrs = Attrs::from(super::Attrs(attrs));
let op = self.op().await?;
@ -94,9 +94,9 @@ impl<'a> Provider for Sftp<'a> {
async fn hard_link<P>(&self, to: P) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
{
let to = to.as_path_dyn().as_os()?;
let to = to.as_path().as_os()?;
Ok(self.op().await?.hardlink(self.path, to).await?)
}
@ -113,7 +113,7 @@ impl<'a> Provider for Sftp<'a> {
}
Url::Sftp { loc, domain } => {
let (name, config) = Vfs::provider::<&ProviderSftp>(domain).await?;
Ok(Self::Me { url, path: loc.as_path(), name, config })
Ok(Self::Me { url, path: loc.as_inner(), name, config })
}
}
}
@ -135,9 +135,9 @@ impl<'a> Provider for Sftp<'a> {
async fn rename<P>(&self, to: P) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
{
let to = to.as_path_dyn().as_os()?;
let to = to.as_path().as_os()?;
let op = self.op().await?;
match op.rename_posix(self.path, &to).await {
@ -153,10 +153,10 @@ impl<'a> Provider for Sftp<'a> {
async fn symlink<P, F>(&self, original: P, _is_dir: F) -> io::Result<()>
where
P: AsPathDyn,
P: AsPath,
F: AsyncFnOnce() -> io::Result<bool>,
{
let original = original.as_path_dyn().as_os()?;
let original = original.as_path().as_os()?;
Ok(self.op().await?.symlink(&original, self.path).await?)
}