Skip to content

Commit a3e9ea0

Browse files
authored
refactor: generalize Loc, LocBuf, Uri, and Urn (#3295)
1 parent 564b885 commit a3e9ea0

File tree

23 files changed

+531
-284
lines changed

23 files changed

+531
-284
lines changed

Cargo.lock

Lines changed: 27 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ansi-to-tui = "7.0.0"
2424
anyhow = "1.0.100"
2525
base64 = "0.22.1"
2626
bitflags = { version = "2.10.0", features = [ "serde" ] }
27-
clap = { version = "4.5.50", features = [ "derive" ] }
27+
clap = { version = "4.5.51", features = [ "derive" ] }
2828
core-foundation-sys = "0.8.7"
2929
crossterm = { version = "0.29.0", features = [ "event-stream" ] }
3030
dirs = "6.0.0"

yazi-actor/src/mgr/create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Create {
5151
&& let Some((parent, urn)) = real.pair()
5252
{
5353
ok_or_not_found!(provider::remove_file(&new).await);
54-
FilesOp::Deleting(parent.into(), [urn.into()].into()).emit();
54+
FilesOp::Deleting(parent.into(), [urn.to_owned()].into()).emit();
5555
provider::create(&new).await?;
5656
} else if let Some(parent) = new.parent() {
5757
provider::create_dir_all(parent).await.ok();
@@ -65,7 +65,7 @@ impl Create {
6565
&& let Some((parent, urn)) = real.pair()
6666
{
6767
let file = File::new(&real).await?;
68-
FilesOp::Upserting(parent.into(), [(urn.into(), file)].into()).emit();
68+
FilesOp::Upserting(parent.into(), [(urn.to_owned(), file)].into()).emit();
6969
MgrProxy::reveal(&real);
7070
}
7171

yazi-actor/src/mgr/hover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Actor for Hover {
2626

2727
// Turn on tracing
2828
if let (Some(h), Some(u)) = (tab.hovered(), opt.urn)
29-
&& *h.urn() == u
29+
&& h.urn() == u
3030
{
3131
// `hover(Some)` occurs after user actions, such as create, rename, reveal, etc.
3232
// At this point, it's intuitive to track the location of the file regardless.

yazi-actor/src/mgr/rename.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ impl Rename {
7373
&& let Some((parent, urn)) = u.pair()
7474
{
7575
ok_or_not_found!(provider::rename(&u, &new).await);
76-
FilesOp::Deleting(parent.to_owned(), [urn.into()].into()).emit();
76+
FilesOp::Deleting(parent.to_owned(), [urn.to_owned()].into()).emit();
7777
}
7878

7979
let new = provider::casefold(&new).await?;
8080
let Some((new_p, new_n)) = new.pair() else { return Ok(()) };
8181

8282
let file = File::new(&new).await?;
8383
if new_p == old_p {
84-
FilesOp::Upserting(old_p.into(), [(old_n.into(), file)].into()).emit();
84+
FilesOp::Upserting(old_p.into(), [(old_n.to_owned(), file)].into()).emit();
8585
} else {
86-
FilesOp::Deleting(old_p.into(), [old_n.into()].into()).emit();
87-
FilesOp::Upserting(new_p.into(), [(new_n.into(), file)].into()).emit();
86+
FilesOp::Deleting(old_p.into(), [old_n.to_owned()].into()).emit();
87+
FilesOp::Upserting(new_p.into(), [(new_n.to_owned(), file)].into()).emit();
8888
}
8989

9090
MgrProxy::reveal(&new);

yazi-actor/src/mgr/reveal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Actor for Reveal {
3131
}
3232

3333
// Now, we can safely hover on the target
34-
act!(mgr:hover, cx, Some(child.into()))?;
34+
act!(mgr:hover, cx, Some(child.to_owned()))?;
3535

3636
act!(mgr:peek, cx)?;
3737
act!(mgr:watch, cx)?;

yazi-binding/src/urn.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
use std::ops::Deref;
1+
use std::{ops::Deref, path::PathBuf};
22

33
use mlua::{ExternalError, FromLua, Lua, UserData, Value};
4+
use yazi_shared::path::PathBufLike;
45

5-
pub struct Urn {
6-
inner: yazi_shared::url::UrnBuf,
6+
pub struct Urn<P: PathBufLike = PathBuf> {
7+
inner: yazi_shared::url::UrnBuf<P>,
78
}
89

9-
impl Deref for Urn {
10-
type Target = yazi_shared::url::UrnBuf;
10+
impl<P> Deref for Urn<P>
11+
where
12+
P: PathBufLike,
13+
{
14+
type Target = yazi_shared::url::UrnBuf<P>;
1115

1216
fn deref(&self) -> &Self::Target { &self.inner }
1317
}
1418

15-
impl From<Urn> for yazi_shared::url::UrnBuf {
16-
fn from(value: Urn) -> Self { value.inner }
19+
impl<P> From<Urn<P>> for yazi_shared::url::UrnBuf<P>
20+
where
21+
P: PathBufLike,
22+
{
23+
fn from(value: Urn<P>) -> Self { value.inner }
1724
}
1825

19-
impl Urn {
20-
pub fn new(urn: impl Into<yazi_shared::url::UrnBuf>) -> Self { Self { inner: urn.into() } }
26+
impl<P> Urn<P>
27+
where
28+
P: PathBufLike,
29+
{
30+
pub fn new(urn: impl Into<yazi_shared::url::UrnBuf<P>>) -> Self { Self { inner: urn.into() } }
2131
}
2232

23-
impl FromLua for Urn {
33+
impl<P> FromLua for Urn<P>
34+
where
35+
P: PathBufLike,
36+
{
2437
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
2538
Ok(match value {
2639
Value::UserData(ud) => ud.take()?,
@@ -29,4 +42,4 @@ impl FromLua for Urn {
2942
}
3043
}
3144

32-
impl UserData for Urn {}
45+
impl<P> UserData for Urn<P> where P: PathBufLike {}

yazi-boot/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ yazi-shared = { path = "../yazi-shared", version = "25.9.15" }
2828

2929
# External dependencies
3030
clap = { workspace = true }
31-
clap_complete = "4.5.59"
31+
clap_complete = "4.5.60"
3232
clap_complete_fig = "4.5.2"
3333
clap_complete_nushell = "4.5.9"
3434
vergen-gitcl = { version = "1.0.8", features = [ "build", "rustc" ] }

yazi-boot/src/boot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Boot {
3838
};
3939

4040
if provider::metadata(&entry).await.is_ok_and(|m| m.is_file()) {
41-
(parent.into(), child.into())
41+
(parent.into(), child.to_owned())
4242
} else {
4343
(entry, UrnBuf::default())
4444
}

yazi-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ yazi-shared = { path = "../yazi-shared", version = "25.9.15" }
4141
# External build dependencies
4242
anyhow = { workspace = true }
4343
clap = { workspace = true }
44-
clap_complete = "4.5.59"
44+
clap_complete = "4.5.60"
4545
clap_complete_fig = "4.5.2"
4646
clap_complete_nushell = "4.5.9"
4747
serde_json = { workspace = true }

0 commit comments

Comments
 (0)