Skip to content

Commit e4c98e9

Browse files
Use Box<Path> in lieu of PathBuf for immutable structs (#12346)
## Summary I don't know if I actually want to commit this, but I did it on the plane last time and just polished it off (got it to compile) while waiting to board.
1 parent 9745b76 commit e4c98e9

File tree

23 files changed

+225
-180
lines changed

23 files changed

+225
-180
lines changed

crates/uv-cache/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ pub enum Refresh {
11851185
/// Don't refresh any entries.
11861186
None(Timestamp),
11871187
/// Refresh entries linked to the given packages, if created before the given timestamp.
1188-
Packages(Vec<PackageName>, Vec<PathBuf>, Timestamp),
1188+
Packages(Vec<PackageName>, Vec<Box<Path>>, Timestamp),
11891189
/// Refresh all entries created before the given timestamp.
11901190
All(Timestamp),
11911191
}

crates/uv-client/src/registry_client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl RegistryClient {
623623
.await?
624624
}
625625
BuiltDist::Path(wheel) => {
626-
let file = fs_err::tokio::File::open(&wheel.install_path)
626+
let file = fs_err::tokio::File::open(wheel.install_path.as_ref())
627627
.await
628628
.map_err(ErrorKind::Io)?;
629629
let reader = tokio::io::BufReader::new(file);

crates/uv-configuration/src/package_options.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::Path;
22

33
use either::Either;
44
use rustc_hash::FxHashMap;
@@ -20,7 +20,7 @@ pub enum Reinstall {
2020
All,
2121

2222
/// Reinstall only the specified packages.
23-
Packages(Vec<PackageName>, Vec<PathBuf>),
23+
Packages(Vec<PackageName>, Vec<Box<Path>>),
2424
}
2525

2626
impl Reinstall {
@@ -89,9 +89,9 @@ impl Reinstall {
8989
}
9090
}
9191

92-
/// Add a [`PathBuf`] to the [`Reinstall`] policy.
92+
/// Add a [`Box<Path>`] to the [`Reinstall`] policy.
9393
#[must_use]
94-
pub fn with_path(self, path: PathBuf) -> Self {
94+
pub fn with_path(self, path: Box<Path>) -> Self {
9595
match self {
9696
Self::None => Self::Packages(vec![], vec![path]),
9797
Self::All => Self::All,

crates/uv-distribution-types/src/cached.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::Path;
22

33
use uv_cache_info::CacheInfo;
44
use uv_distribution_filename::WheelFilename;
@@ -22,7 +22,7 @@ pub enum CachedDist {
2222
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
2323
pub struct CachedRegistryDist {
2424
pub filename: WheelFilename,
25-
pub path: PathBuf,
25+
pub path: Box<Path>,
2626
pub hashes: HashDigests,
2727
pub cache_info: CacheInfo,
2828
}
@@ -31,7 +31,7 @@ pub struct CachedRegistryDist {
3131
pub struct CachedDirectUrlDist {
3232
pub filename: WheelFilename,
3333
pub url: VerbatimParsedUrl,
34-
pub path: PathBuf,
34+
pub path: Box<Path>,
3535
pub hashes: HashDigests,
3636
pub cache_info: CacheInfo,
3737
}
@@ -43,7 +43,7 @@ impl CachedDist {
4343
filename: WheelFilename,
4444
hashes: HashDigests,
4545
cache_info: CacheInfo,
46-
path: PathBuf,
46+
path: Box<Path>,
4747
) -> Self {
4848
match remote {
4949
Dist::Built(BuiltDist::Registry(_dist)) => Self::Registry(CachedRegistryDist {

crates/uv-distribution-types/src/installed.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub enum InstalledDist {
7777
pub struct InstalledRegistryDist {
7878
pub name: PackageName,
7979
pub version: Version,
80-
pub path: PathBuf,
80+
pub path: Box<Path>,
8181
pub cache_info: Option<CacheInfo>,
8282
}
8383

@@ -88,32 +88,32 @@ pub struct InstalledDirectUrlDist {
8888
pub direct_url: Box<DirectUrl>,
8989
pub url: Url,
9090
pub editable: bool,
91-
pub path: PathBuf,
91+
pub path: Box<Path>,
9292
pub cache_info: Option<CacheInfo>,
9393
}
9494

9595
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
9696
pub struct InstalledEggInfoFile {
9797
pub name: PackageName,
9898
pub version: Version,
99-
pub path: PathBuf,
99+
pub path: Box<Path>,
100100
}
101101

102102
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
103103
pub struct InstalledEggInfoDirectory {
104104
pub name: PackageName,
105105
pub version: Version,
106-
pub path: PathBuf,
106+
pub path: Box<Path>,
107107
}
108108

109109
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
110110
pub struct InstalledLegacyEditable {
111111
pub name: PackageName,
112112
pub version: Version,
113-
pub egg_link: PathBuf,
114-
pub target: PathBuf,
113+
pub egg_link: Box<Path>,
114+
pub target: Box<Path>,
115115
pub target_url: Url,
116-
pub egg_info: PathBuf,
116+
pub egg_info: Box<Path>,
117117
}
118118

119119
impl InstalledDist {
@@ -145,15 +145,15 @@ impl InstalledDist {
145145
editable: matches!(&direct_url, DirectUrl::LocalDirectory { dir_info, .. } if dir_info.editable == Some(true)),
146146
direct_url: Box::new(direct_url),
147147
url,
148-
path: path.to_path_buf(),
148+
path: path.to_path_buf().into_boxed_path(),
149149
cache_info,
150150
}))),
151151
Err(err) => {
152152
warn!("Failed to parse direct URL: {err}");
153153
Ok(Some(Self::Registry(InstalledRegistryDist {
154154
name,
155155
version,
156-
path: path.to_path_buf(),
156+
path: path.to_path_buf().into_boxed_path(),
157157
cache_info,
158158
})))
159159
}
@@ -162,7 +162,7 @@ impl InstalledDist {
162162
Ok(Some(Self::Registry(InstalledRegistryDist {
163163
name,
164164
version,
165-
path: path.to_path_buf(),
165+
path: path.to_path_buf().into_boxed_path(),
166166
cache_info,
167167
})))
168168
};
@@ -191,15 +191,15 @@ impl InstalledDist {
191191
return Ok(Some(Self::EggInfoDirectory(InstalledEggInfoDirectory {
192192
name: file_name.name,
193193
version,
194-
path: path.to_path_buf(),
194+
path: path.to_path_buf().into_boxed_path(),
195195
})));
196196
}
197197

198198
if metadata.is_file() {
199199
return Ok(Some(Self::EggInfoFile(InstalledEggInfoFile {
200200
name: file_name.name,
201201
version,
202-
path: path.to_path_buf(),
202+
path: path.to_path_buf().into_boxed_path(),
203203
})));
204204
}
205205
};
@@ -211,7 +211,7 @@ impl InstalledDist {
211211
return Ok(Some(Self::EggInfoDirectory(InstalledEggInfoDirectory {
212212
name: file_name.name,
213213
version: Version::from_str(&egg_metadata.version)?,
214-
path: path.to_path_buf(),
214+
path: path.to_path_buf().into_boxed_path(),
215215
})));
216216
}
217217

@@ -222,7 +222,7 @@ impl InstalledDist {
222222
return Ok(Some(Self::EggInfoDirectory(InstalledEggInfoDirectory {
223223
name: file_name.name,
224224
version: Version::from_str(&egg_metadata.version)?,
225-
path: path.to_path_buf(),
225+
path: path.to_path_buf().into_boxed_path(),
226226
})));
227227
}
228228
}
@@ -270,10 +270,10 @@ impl InstalledDist {
270270
return Ok(Some(Self::LegacyEditable(InstalledLegacyEditable {
271271
name: egg_metadata.name,
272272
version: Version::from_str(&egg_metadata.version)?,
273-
egg_link: path.to_path_buf(),
274-
target,
273+
egg_link: path.to_path_buf().into_boxed_path(),
274+
target: target.into_boxed_path(),
275275
target_url: url,
276-
egg_info,
276+
egg_info: egg_info.into_boxed_path(),
277277
})));
278278
}
279279

@@ -344,7 +344,7 @@ impl InstalledDist {
344344
}
345345
Self::EggInfoFile(_) | Self::EggInfoDirectory(_) | Self::LegacyEditable(_) => {
346346
let path = match self {
347-
Self::EggInfoFile(dist) => Cow::Borrowed(&dist.path),
347+
Self::EggInfoFile(dist) => Cow::Borrowed(&*dist.path),
348348
Self::EggInfoDirectory(dist) => Cow::Owned(dist.path.join("PKG-INFO")),
349349
Self::LegacyEditable(dist) => Cow::Owned(dist.egg_info.join("PKG-INFO")),
350350
_ => unreachable!(),

crates/uv-distribution-types/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//! Since we read this information from [`direct_url.json`](https://packaging.python.org/en/latest/specifications/direct-url-data-structure/), it doesn't match the information [`Dist`] exactly.
3535
use std::borrow::Cow;
3636
use std::path;
37-
use std::path::{Path, PathBuf};
37+
use std::path::Path;
3838
use std::str::FromStr;
3939

4040
use url::Url;
@@ -266,7 +266,7 @@ pub struct DirectUrlBuiltDist {
266266
pub struct PathBuiltDist {
267267
pub filename: WheelFilename,
268268
/// The absolute path to the wheel which we use for installing.
269-
pub install_path: PathBuf,
269+
pub install_path: Box<Path>,
270270
/// The URL as it was provided by the user.
271271
pub url: VerbatimUrl,
272272
}
@@ -299,7 +299,7 @@ pub struct DirectUrlSourceDist {
299299
/// The URL without the subdirectory fragment.
300300
pub location: Box<Url>,
301301
/// The subdirectory within the archive in which the source distribution is located.
302-
pub subdirectory: Option<PathBuf>,
302+
pub subdirectory: Option<Box<Path>>,
303303
/// The file extension, e.g. `tar.gz`, `zip`, etc.
304304
pub ext: SourceDistExtension,
305305
/// The URL as it was provided by the user, including the subdirectory fragment.
@@ -313,7 +313,7 @@ pub struct GitSourceDist {
313313
/// The URL without the revision and subdirectory fragment.
314314
pub git: Box<GitUrl>,
315315
/// The subdirectory within the Git repository in which the source distribution is located.
316-
pub subdirectory: Option<PathBuf>,
316+
pub subdirectory: Option<Box<Path>>,
317317
/// The URL as it was provided by the user, including the revision and subdirectory fragment.
318318
pub url: VerbatimUrl,
319319
}
@@ -324,7 +324,7 @@ pub struct PathSourceDist {
324324
pub name: PackageName,
325325
pub version: Option<Version>,
326326
/// The absolute path to the distribution which we use for installing.
327-
pub install_path: PathBuf,
327+
pub install_path: Box<Path>,
328328
/// The file extension, e.g. `tar.gz`, `zip`, etc.
329329
pub ext: SourceDistExtension,
330330
/// The URL as it was provided by the user.
@@ -336,7 +336,7 @@ pub struct PathSourceDist {
336336
pub struct DirectorySourceDist {
337337
pub name: PackageName,
338338
/// The absolute path to the distribution which we use for installing.
339-
pub install_path: PathBuf,
339+
pub install_path: Box<Path>,
340340
/// Whether the package should be installed in editable mode.
341341
pub editable: bool,
342342
/// Whether the package should be built and installed.
@@ -352,7 +352,7 @@ impl Dist {
352352
name: PackageName,
353353
url: VerbatimUrl,
354354
location: Url,
355-
subdirectory: Option<PathBuf>,
355+
subdirectory: Option<Box<Path>>,
356356
ext: DistExtension,
357357
) -> Result<Dist, Error> {
358358
match ext {
@@ -417,7 +417,7 @@ impl Dist {
417417
}
418418
Ok(Self::Built(BuiltDist::Path(PathBuiltDist {
419419
filename,
420-
install_path,
420+
install_path: install_path.into_boxed_path(),
421421
url,
422422
})))
423423
}
@@ -434,7 +434,7 @@ impl Dist {
434434
Ok(Self::Source(SourceDist::Path(PathSourceDist {
435435
name,
436436
version,
437-
install_path,
437+
install_path: install_path.into_boxed_path(),
438438
ext,
439439
url,
440440
})))
@@ -464,7 +464,7 @@ impl Dist {
464464
// Determine whether the path represents an archive or a directory.
465465
Ok(Self::Source(SourceDist::Directory(DirectorySourceDist {
466466
name,
467-
install_path,
467+
install_path: install_path.into_boxed_path(),
468468
editable,
469469
r#virtual,
470470
url,
@@ -476,7 +476,7 @@ impl Dist {
476476
name: PackageName,
477477
url: VerbatimUrl,
478478
git: GitUrl,
479-
subdirectory: Option<PathBuf>,
479+
subdirectory: Option<Box<Path>>,
480480
) -> Result<Dist, Error> {
481481
Ok(Self::Source(SourceDist::Git(GitSourceDist {
482482
name,

0 commit comments

Comments
 (0)