mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Optimize binary size/compilation time
by reducing generics monomorphization using `Box<dyn Trait>`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
bd39ce754f
commit
3a1038c80b
1 changed files with 48 additions and 41 deletions
|
@ -109,14 +109,9 @@ impl<T: Debug + Send + 'static> AsyncExtracterInner<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn extract_impl<
|
async fn extract_impl<T: Debug + Send + 'static, S: Stream<Item = Result<Bytes, E>> + Unpin, E>(
|
||||||
F: FnOnce(mpsc::Receiver<Content>) -> Result<T, BinstallError> + Send + 'static,
|
|
||||||
T: Debug + Send + 'static,
|
|
||||||
S: Stream<Item = Result<Bytes, E>> + Unpin,
|
|
||||||
E,
|
|
||||||
>(
|
|
||||||
mut stream: S,
|
mut stream: S,
|
||||||
f: F,
|
f: Box<dyn FnOnce(mpsc::Receiver<Content>) -> Result<T, BinstallError> + Send>,
|
||||||
) -> Result<T, BinstallError>
|
) -> Result<T, BinstallError>
|
||||||
where
|
where
|
||||||
BinstallError: From<E>,
|
BinstallError: From<E>,
|
||||||
|
@ -155,7 +150,9 @@ where
|
||||||
{
|
{
|
||||||
let path = output.to_owned();
|
let path = output.to_owned();
|
||||||
|
|
||||||
extract_impl(stream, move |mut rx| {
|
extract_impl(
|
||||||
|
stream,
|
||||||
|
Box::new(move |mut rx| {
|
||||||
fs::create_dir_all(path.parent().unwrap())?;
|
fs::create_dir_all(path.parent().unwrap())?;
|
||||||
|
|
||||||
let mut file = fs::File::create(&path)?;
|
let mut file = fs::File::create(&path)?;
|
||||||
|
@ -173,7 +170,8 @@ where
|
||||||
ScopeGuard::into_inner(remove_guard);
|
ScopeGuard::into_inner(remove_guard);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
}),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +184,9 @@ where
|
||||||
{
|
{
|
||||||
let path = output.to_owned();
|
let path = output.to_owned();
|
||||||
|
|
||||||
extract_impl(stream, move |mut rx| {
|
extract_impl(
|
||||||
|
stream,
|
||||||
|
Box::new(move |mut rx| {
|
||||||
fs::create_dir_all(path.parent().unwrap())?;
|
fs::create_dir_all(path.parent().unwrap())?;
|
||||||
|
|
||||||
let mut file = tempfile()?;
|
let mut file = tempfile()?;
|
||||||
|
@ -197,7 +197,8 @@ where
|
||||||
file.rewind()?;
|
file.rewind()?;
|
||||||
|
|
||||||
unzip(file, &path)
|
unzip(file, &path)
|
||||||
})
|
}),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +220,9 @@ where
|
||||||
|
|
||||||
let path = output.to_owned();
|
let path = output.to_owned();
|
||||||
|
|
||||||
extract_impl(stream, move |mut rx| {
|
extract_impl(
|
||||||
|
stream,
|
||||||
|
Box::new(move |mut rx| {
|
||||||
fs::create_dir_all(path.parent().unwrap())?;
|
fs::create_dir_all(path.parent().unwrap())?;
|
||||||
|
|
||||||
extract_compressed_from_readable::<DummyVisitor, _>(
|
extract_compressed_from_readable::<DummyVisitor, _>(
|
||||||
|
@ -227,7 +230,8 @@ where
|
||||||
fmt,
|
fmt,
|
||||||
Op::UnpackToPath(&path),
|
Op::UnpackToPath(&path),
|
||||||
)
|
)
|
||||||
})
|
}),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,9 +243,12 @@ pub async fn extract_tar_based_stream_and_visit<V: TarEntriesVisitor + Debug + S
|
||||||
where
|
where
|
||||||
BinstallError: From<E>,
|
BinstallError: From<E>,
|
||||||
{
|
{
|
||||||
extract_impl(stream, move |mut rx| {
|
extract_impl(
|
||||||
|
stream,
|
||||||
|
Box::new(move |mut rx| {
|
||||||
extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt, Op::Visit(&mut visitor))
|
extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt, Op::Visit(&mut visitor))
|
||||||
.map(|_| visitor)
|
.map(|_| visitor)
|
||||||
})
|
}),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue