Skip to content

Commit 1caf1de

Browse files
committed
Use dyn
1 parent 6e8114a commit 1caf1de

File tree

18 files changed

+87
-57
lines changed

18 files changed

+87
-57
lines changed

crates/uv-distribution/src/distribution_database.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
7272

7373
/// Set the [`Reporter`] to use for this source distribution fetcher.
7474
#[must_use]
75-
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
76-
let reporter = Arc::new(reporter);
75+
pub fn with_reporter(self, reporter: Arc<dyn Reporter>) -> Self {
7776
Self {
7877
reporter: Some(reporter.clone()),
7978
builder: self.builder.with_reporter(reporter),

crates/uv-distribution/src/source/mod.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,11 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
13191319
resource.git,
13201320
client.unmanaged.uncached_client(resource.url).clone(),
13211321
self.build_context.cache().bucket(CacheBucket::Git),
1322-
self.reporter.clone().map(Facade::from),
1322+
self.reporter
1323+
.clone()
1324+
.map(Facade::from)
1325+
.map(Arc::new)
1326+
.map(|reporter| reporter as _),
13231327
)
13241328
.await?;
13251329

@@ -1416,7 +1420,11 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
14161420
resource.git,
14171421
client.unmanaged.uncached_client(resource.url).clone(),
14181422
self.build_context.cache().bucket(CacheBucket::Git),
1419-
self.reporter.clone().map(Facade::from),
1423+
self.reporter
1424+
.clone()
1425+
.map(Facade::from)
1426+
.map(Arc::new)
1427+
.map(|reporter| reporter as _),
14201428
)
14211429
.await?;
14221430

@@ -1592,7 +1600,11 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
15921600
&source.git,
15931601
client.unmanaged.uncached_client(&source.url).clone(),
15941602
self.build_context.cache().bucket(CacheBucket::Git),
1595-
self.reporter.clone().map(Facade::from),
1603+
self.reporter
1604+
.clone()
1605+
.map(Facade::from)
1606+
.map(Arc::new)
1607+
.map(|reporter| reporter as _),
15961608
)
15971609
.await?;
15981610
}
@@ -1603,7 +1615,11 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
16031615
source.git,
16041616
client.unmanaged.uncached_client(source.url).clone(),
16051617
self.build_context.cache().bucket(CacheBucket::Git),
1606-
self.reporter.clone().map(Facade::from),
1618+
self.reporter
1619+
.clone()
1620+
.map(Facade::from)
1621+
.map(Arc::new)
1622+
.map(|reporter| reporter as _),
16071623
)
16081624
.await?;
16091625
}

crates/uv-git/src/resolver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl GitResolver {
4444
url: &GitUrl,
4545
client: ClientWithMiddleware,
4646
cache: PathBuf,
47-
reporter: Option<impl Reporter + 'static>,
47+
reporter: Option<Arc<dyn Reporter>>,
4848
) -> Result<GitSha, GitResolverError> {
4949
debug!("Resolving source distribution from Git: {url}");
5050

@@ -88,7 +88,7 @@ impl GitResolver {
8888
url: &GitUrl,
8989
client: ClientWithMiddleware,
9090
cache: PathBuf,
91-
reporter: Option<impl Reporter + 'static>,
91+
reporter: Option<Arc<dyn Reporter>>,
9292
) -> Result<Fetch, GitResolverError> {
9393
debug!("Fetching source distribution from Git: {url}");
9494

@@ -138,7 +138,7 @@ impl GitResolver {
138138
/// For example, given a Git dependency with a reference to a branch or tag, return a URL
139139
/// with a precise reference to the current commit of that branch or tag.
140140
///
141-
/// This method takes into account various normalizations that are independent from the Git
141+
/// This method takes into account various normalizations that are independent of the Git
142142
/// layer. For example: removing `#subdirectory=pkg_dir`-like fragments, and removing `git+`
143143
/// prefix kinds.
144144
///

crates/uv-git/src/source.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
//! Cargo is dual-licensed under either Apache 2.0 or MIT, at the user's choice.
33
//! Source: <https://github.com/rust-lang/cargo/blob/23eb492cf920ce051abfc56bbaf838514dc8365c/src/cargo/sources/git/source.rs>
44
5-
use std::borrow::Cow;
6-
use std::path::{Path, PathBuf};
7-
85
use anyhow::Result;
96
use reqwest_middleware::ClientWithMiddleware;
7+
use std::borrow::Cow;
8+
use std::path::{Path, PathBuf};
9+
use std::sync::Arc;
1010
use tracing::{debug, instrument};
1111
use url::Url;
1212

@@ -24,11 +24,11 @@ pub struct GitSource {
2424
/// The path to the Git source database.
2525
cache: PathBuf,
2626
/// The reporter to use for this source.
27-
reporter: Option<Box<dyn Reporter>>,
27+
reporter: Option<Arc<dyn Reporter>>,
2828
}
2929

3030
impl GitSource {
31-
/// Initialize a new Git source.
31+
/// Initialize a [`GitSource`] with the given Git URL, HTTP client, and cache path.
3232
pub fn new(
3333
git: GitUrl,
3434
client: impl Into<ClientWithMiddleware>,
@@ -42,11 +42,11 @@ impl GitSource {
4242
}
4343
}
4444

45-
/// Set the [`Reporter`] to use for this `GIt` source.
45+
/// Set the [`Reporter`] to use for the [`GitSource`].
4646
#[must_use]
47-
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
47+
pub fn with_reporter(self, reporter: Arc<dyn Reporter>) -> Self {
4848
Self {
49-
reporter: Some(Box::new(reporter)),
49+
reporter: Some(reporter),
5050
..self
5151
}
5252
}

crates/uv-installer/src/installer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{Context, Error, Result};
22
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
33
use std::convert;
4-
use std::sync::LazyLock;
4+
use std::sync::{Arc, LazyLock};
55
use tokio::sync::oneshot;
66
use tracing::instrument;
77
use uv_install_wheel::{linker::LinkMode, Layout};
@@ -15,7 +15,7 @@ pub struct Installer<'a> {
1515
venv: &'a PythonEnvironment,
1616
link_mode: LinkMode,
1717
cache: Option<&'a Cache>,
18-
reporter: Option<Box<dyn Reporter>>,
18+
reporter: Option<Arc<dyn Reporter>>,
1919
installer_name: Option<String>,
2020
installer_metadata: bool,
2121
}
@@ -50,9 +50,9 @@ impl<'a> Installer<'a> {
5050

5151
/// Set the [`Reporter`] to use for this installer.
5252
#[must_use]
53-
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
53+
pub fn with_reporter(self, reporter: Arc<dyn Reporter>) -> Self {
5454
Self {
55-
reporter: Some(Box::new(reporter)),
55+
reporter: Some(reporter),
5656
..self
5757
}
5858
}
@@ -66,7 +66,7 @@ impl<'a> Installer<'a> {
6666
}
6767
}
6868

69-
/// Set the whether to link Uv specific files in dist-info
69+
/// Set whether to install uv-specifier files in the dist-info directory.
7070
#[must_use]
7171
pub fn with_installer_metadata(self, installer_metadata: bool) -> Self {
7272
Self {
@@ -151,7 +151,7 @@ fn install(
151151
layout: Layout,
152152
installer_name: Option<String>,
153153
link_mode: LinkMode,
154-
reporter: Option<Box<dyn Reporter>>,
154+
reporter: Option<Arc<dyn Reporter>>,
155155
relocatable: bool,
156156
installer_metadata: bool,
157157
) -> Result<Vec<CachedDist>> {

crates/uv-installer/src/preparer.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@ impl<'a, Context: BuildContext> Preparer<'a, Context> {
4848

4949
/// Set the [`Reporter`] to use for operations.
5050
#[must_use]
51-
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
52-
let reporter: Arc<dyn Reporter> = Arc::new(reporter);
51+
pub fn with_reporter(self, reporter: Arc<dyn Reporter>) -> Self {
5352
Self {
5453
tags: self.tags,
5554
cache: self.cache,
5655
hashes: self.hashes,
5756
build_options: self.build_options,
58-
database: self.database.with_reporter(Facade::from(reporter.clone())),
59-
reporter: Some(reporter.clone()),
57+
database: self
58+
.database
59+
.with_reporter(Arc::new(Facade::from(reporter.clone()))),
60+
reporter: Some(reporter),
6061
}
6162
}
6263

@@ -269,7 +270,7 @@ pub trait Reporter: Send + Sync {
269270
fn on_checkout_complete(&self, url: &Url, rev: &str, index: usize);
270271
}
271272

272-
/// A facade for converting from [`Reporter`] to [`uv_git::Reporter`].
273+
/// A facade for converting from [`Reporter`] to [`uv_distribution::Reporter`].
273274
struct Facade {
274275
reporter: Arc<dyn Reporter>,
275276
}

crates/uv-requirements/src/extras.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, Context: BuildContext> ExtrasResolver<'a, Context> {
3737

3838
/// Set the [`Reporter`] to use for this resolver.
3939
#[must_use]
40-
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
40+
pub fn with_reporter(self, reporter: Arc<dyn Reporter>) -> Self {
4141
Self {
4242
database: self.database.with_reporter(reporter),
4343
..self

crates/uv-requirements/src/lookahead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a, Context: BuildContext> LookaheadResolver<'a, Context> {
6767

6868
/// Set the [`Reporter`] to use for this resolver.
6969
#[must_use]
70-
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
70+
pub fn with_reporter(self, reporter: Arc<dyn Reporter>) -> Self {
7171
Self {
7272
database: self.database.with_reporter(reporter),
7373
..self

crates/uv-requirements/src/source_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a, Context: BuildContext> SourceTreeResolver<'a, Context> {
6565

6666
/// Set the [`Reporter`] to use for this resolver.
6767
#[must_use]
68-
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
68+
pub fn with_reporter(self, reporter: Arc<dyn Reporter>) -> Self {
6969
Self {
7070
database: self.database.with_reporter(reporter),
7171
..self

crates/uv-requirements/src/unnamed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, Context: BuildContext> NamedRequirementsResolver<'a, Context> {
4949

5050
/// Set the [`Reporter`] to use for this resolver.
5151
#[must_use]
52-
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
52+
pub fn with_reporter(self, reporter: Arc<dyn Reporter>) -> Self {
5353
Self {
5454
database: self.database.with_reporter(reporter),
5555
..self

0 commit comments

Comments
 (0)