-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rust): avoid unnecessary clone on
external
(#1092)
- Loading branch information
Showing
8 changed files
with
79 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
crates/rolldown_common/src/inner_bundler_options/types/external.rs
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
crates/rolldown_common/src/inner_bundler_options/types/is_external.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::fmt::Debug; | ||
use std::future::Future; | ||
use std::ops::Deref; | ||
use std::pin::Pin; | ||
|
||
type Inner = dyn Fn( | ||
&str, // specifier | ||
Option<&str>, // importer | ||
bool, // is_resolved | ||
) -> Pin<Box<(dyn Future<Output = anyhow::Result<bool>> + Send + 'static)>> | ||
+ Send | ||
+ Sync | ||
+ 'static; | ||
|
||
pub struct IsExternal(Box<Inner>); | ||
|
||
impl Deref for IsExternal { | ||
type Target = Inner; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&*self.0 | ||
} | ||
} | ||
|
||
impl IsExternal { | ||
pub fn from_closure<F>(f: F) -> Self | ||
where | ||
F: Fn( | ||
&str, // specifier | ||
Option<&str>, // importer | ||
bool, // is_resolved | ||
) -> Pin<Box<(dyn Future<Output = anyhow::Result<bool>> + Send + 'static)>> | ||
+ Send | ||
+ Sync | ||
+ 'static, | ||
{ | ||
Self(Box::new(f)) | ||
} | ||
|
||
pub fn from_vec(value: Vec<String>) -> Self { | ||
Self::from_closure(move |source, _, _| { | ||
let result = value.iter().any(|item| item == source); | ||
Box::pin(async move { Ok(result) }) | ||
}) | ||
} | ||
} | ||
|
||
impl From<Vec<String>> for IsExternal { | ||
fn from(value: Vec<String>) -> Self { | ||
IsExternal::from_vec(value) | ||
} | ||
} | ||
|
||
impl Debug for IsExternal { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "IsExternal(...)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters