Skip to content

Commit 449450d

Browse files
committed
feat!: introduce Path as a subset of Url to enforce type safety (#3361)
1 parent 76fe6d7 commit 449450d

File tree

10 files changed

+28
-24
lines changed

10 files changed

+28
-24
lines changed

.github/workflows/cachix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
os: [ubuntu-latest, macos-latest]
1313
runs-on: ${{ matrix.os }}
1414
steps:
15-
- uses: actions/checkout@v5
15+
- uses: actions/checkout@v6
1616

1717
- name: Install Nix
1818
uses: cachix/install-nix-action@v31

.github/workflows/check.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
clippy:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v5
17+
- uses: actions/checkout@v6
1818

1919
- name: Setup Rust toolchain
2020
run: |
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- name: Checkout
34-
uses: actions/checkout@v5
34+
uses: actions/checkout@v6
3535

3636
- name: Setup Rust toolchain
3737
run: |
@@ -47,7 +47,7 @@ jobs:
4747
stylua:
4848
runs-on: ubuntu-22.04
4949
steps:
50-
- uses: actions/checkout@v5
50+
- uses: actions/checkout@v6
5151
- uses: JohnnyMorganz/stylua-action@v4
5252
with:
5353
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/draft.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER: riscv64-linux-gnu-gcc
4040
CARGO_TARGET_SPARC64_UNKNOWN_LINUX_GNU_LINKER: sparc64-linux-gnu-gcc
4141
steps:
42-
- uses: actions/checkout@v5
42+
- uses: actions/checkout@v6
4343

4444
- name: Install gcc
4545
if: matrix.gcc != ''
@@ -78,7 +78,7 @@ jobs:
7878
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: lld-link.exe
7979
CARGO_TARGET_AARCH64_PC_WINDOWS_MSVC_LINKER: lld-link.exe
8080
steps:
81-
- uses: actions/checkout@v5
81+
- uses: actions/checkout@v6
8282

8383
- uses: dtolnay/rust-toolchain@stable
8484
with:
@@ -117,7 +117,7 @@ jobs:
117117
container:
118118
image: docker://ghcr.io/cross-rs/${{ matrix.target }}:edge
119119
steps:
120-
- uses: actions/checkout@v5
120+
- uses: actions/checkout@v6
121121

122122
- uses: dtolnay/rust-toolchain@stable
123123
with:
@@ -147,7 +147,7 @@ jobs:
147147
arch: arm64
148148
runs-on: ${{ matrix.os }}
149149
steps:
150-
- uses: actions/checkout@v5
150+
- uses: actions/checkout@v6
151151
with:
152152
fetch-depth: 0
153153

@@ -229,7 +229,7 @@ jobs:
229229
echo "Generated on: $(date -u +"%Y-%m-%d %H:%M") UTC" >> $GITHUB_ENV
230230
echo "EOF" >> $GITHUB_ENV
231231
232-
- uses: actions/checkout@v5
232+
- uses: actions/checkout@v6
233233

234234
- uses: actions/download-artifact@v6
235235
with:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
os: [ubuntu-latest, windows-latest, macos-latest]
1919
runs-on: ${{ matrix.os }}
2020
steps:
21-
- uses: actions/checkout@v5
21+
- uses: actions/checkout@v6
2222

2323
- name: Setup Rust toolchain
2424
run: rustup toolchain install stable --profile minimal

.github/workflows/validate-form.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
permissions:
1313
issues: write
1414
steps:
15-
- uses: actions/checkout@v5
15+
- uses: actions/checkout@v6
1616

1717
- name: Setup Node.js
1818
uses: actions/setup-node@v6

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
4545
- Rename `name` to `url` for open, fetchers, spotters, preloaders, previewers, filetype, and `globs` icon rules to support virtual file system ([#3034])
4646
- Rename `mime` fetcher to `mime.local`, and introduce `mime.dir` fetcher to support folder MIME types ([#3222])
4747
- Remove `$0` parameter in opener rules to make the `open` command work under empty directories ([#3226])
48+
- Return `Path` instead of `Url` from `Url:strip_prefix()` to enforce type safety ([#3361])
4849
- Use `body` instead of the term `content` in confirmations ([#2921])
4950
- Use `u16` instead of `u32` as the type of `max_width` and `max_height` options to avoid memory exhaustion ([#3313])
5051
- Implement `__pairs` metamethod instead of `__index` for the callback argument of the `@yank` DDS event ([#2997])

yazi-binding/src/path.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ impl UserData for Path {
115115
cached_field!(fields, stem, |lua, me| {
116116
me.stem().map(|s| lua.create_string(s.encoded_bytes())).transpose()
117117
});
118+
119+
fields.add_field_method_get("is_absolute", |_, me| Ok(me.is_absolute()));
120+
fields.add_field_method_get("has_root", |_, me| Ok(me.has_root()));
118121
}
119122

120123
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {

yazi-boot/src/boot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ use std::path::PathBuf;
22

33
use futures::executor::block_on;
44
use hashbrown::HashSet;
5-
use serde::Serialize;
65
use yazi_fs::{CWD, Xdg, path::expand_url};
76
use yazi_shared::{strand::StrandBuf, url::{UrlBuf, UrlLike}};
87
use yazi_vfs::provider;
98

10-
#[derive(Debug, Default, Serialize)]
9+
#[derive(Debug, Default)]
1110
pub struct Boot {
1211
pub cwds: Vec<UrlBuf>,
1312
pub files: Vec<StrandBuf>,

yazi-shared/src/strand/buf.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use std::{borrow::Cow, ffi::OsString};
1+
use std::{borrow::Cow, ffi::OsString, hash::{Hash, Hasher}};
22

33
use anyhow::Result;
4-
use serde::Serialize;
54

65
use crate::{FromWtf8Vec, path::PathDyn, strand::{AsStrand, Strand, StrandCow, StrandError, StrandKind}};
76

87
// --- StrandBuf
9-
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
10-
#[serde(untagged)]
8+
#[derive(Clone, Debug, Eq)]
119
pub enum StrandBuf {
1210
Os(OsString),
1311
Utf8(String),
@@ -43,10 +41,18 @@ impl From<StrandCow<'_>> for StrandBuf {
4341
fn from(value: StrandCow<'_>) -> Self { value.into_owned() }
4442
}
4543

44+
impl PartialEq for StrandBuf {
45+
fn eq(&self, other: &Self) -> bool { self.as_strand() == other.as_strand() }
46+
}
47+
4648
impl PartialEq<Strand<'_>> for StrandBuf {
4749
fn eq(&self, other: &Strand<'_>) -> bool { self.as_strand() == *other }
4850
}
4951

52+
impl Hash for StrandBuf {
53+
fn hash<H: Hasher>(&self, state: &mut H) { self.as_strand().hash(state); }
54+
}
55+
5056
impl StrandBuf {
5157
pub fn clear(&mut self) {
5258
match self {

yazi-shared/src/strand/cow.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{borrow::Cow, ffi::{OsStr, OsString}};
22

33
use anyhow::Result;
44

5-
use crate::strand::{Strand, StrandBuf, StrandKind};
5+
use crate::strand::{AsStrand, Strand, StrandBuf, StrandKind};
66

77
pub enum StrandCow<'a> {
88
Borrowed(Strand<'a>),
@@ -35,12 +35,7 @@ impl From<StrandBuf> for StrandCow<'_> {
3535
}
3636

3737
impl PartialEq<Strand<'_>> for StrandCow<'_> {
38-
fn eq(&self, other: &Strand) -> bool {
39-
match self {
40-
Self::Borrowed(s) => s == other,
41-
Self::Owned(s) => s == other,
42-
}
43-
}
38+
fn eq(&self, other: &Strand) -> bool { self.as_strand() == *other }
4439
}
4540

4641
impl<'a> StrandCow<'a> {

0 commit comments

Comments
 (0)