Skip to content

Commit

Permalink
feat: use Box<dyn> in sparse functions (#39)
Browse files Browse the repository at this point in the history
To avoid boxing twice in case that an argument is already a box.
  • Loading branch information
DaniPopes authored Jan 4, 2024
1 parent 78a8f9f commit 38afb36
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,9 @@ impl<T: ArtifactOutput> Project<T> {
/// let output = project.compile_sparse(|path: &Path| path.ends_with("Greeter.sol")).unwrap();
/// # }
/// ```
pub fn compile_sparse<F: FileFilter + 'static>(
&self,
filter: F,
) -> Result<ProjectCompileOutput<T>> {
pub fn compile_sparse(&self, filter: Box<dyn FileFilter>) -> Result<ProjectCompileOutput<T>> {
let sources =
Source::read_all(self.paths.input_files().into_iter().filter(|p| filter.is_match(p)))?;
let filter: Box<dyn FileFilter> = Box::new(filter);

#[cfg(all(feature = "svm-solc", not(target_arch = "wasm32")))]
if self.auto_detect {
Expand Down
5 changes: 1 addition & 4 deletions src/project_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ impl<T: ArtifactOutput> TempProject<T> {
self.project().compile()
}

pub fn compile_sparse<F: FileFilter + 'static>(
&self,
filter: F,
) -> Result<ProjectCompileOutput<T>> {
pub fn compile_sparse(&self, filter: Box<dyn FileFilter>) -> Result<ProjectCompileOutput<T>> {
self.project().compile_sparse(filter)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ fn can_compile_sparse_with_link_references() {
)
.unwrap();

let mut compiled = tmp.compile_sparse(TestFileFilter::default()).unwrap();
let mut compiled = tmp.compile_sparse(Box::<TestFileFilter>::default()).unwrap();
compiled.assert_success();

let mut output = compiled.clone().output();
Expand Down

0 comments on commit 38afb36

Please sign in to comment.