diff --git a/src/helpers.rs b/src/helpers.rs index c31884f1..fd014acb 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,14 +1,9 @@ use std::{ fs, - future::Future, - io::{self, stderr, stdin, Write}, - ops::{Deref, DerefMut}, + io::{stderr, stdin, Write}, path::{Path, PathBuf}, - pin::Pin, - task::{Context, Poll}, }; -use bytes::Bytes; use cargo_toml::Manifest; use flate2::read::GzDecoder; use futures_util::stream::StreamExt; @@ -18,7 +13,6 @@ use scopeguard::ScopeGuard; use serde::Serialize; use tar::Archive; use tinytemplate::TinyTemplate; -use tokio::{sync::mpsc, task}; use url::Url; use xz2::read::XzDecoder; use zip::read::ZipArchive; @@ -29,6 +23,9 @@ use crate::{BinstallError, Meta, PkgFmt}; mod async_file_writer; pub use async_file_writer::AsyncFileWriter; +mod auto_abort_join_handle; +pub use auto_abort_join_handle::AutoAbortJoinHandle; + /// Load binstall metadata from the crate `Cargo.toml` at the provided path pub fn load_manifest_path>( manifest_path: P, @@ -233,40 +230,3 @@ pub trait Template: Serialize { Ok(tt.render("path", self)?) } } - -#[derive(Debug)] -pub struct AutoAbortJoinHandle(task::JoinHandle); - -impl AutoAbortJoinHandle { - pub fn new(handle: task::JoinHandle) -> Self { - Self(handle) - } -} - -impl Drop for AutoAbortJoinHandle { - fn drop(&mut self) { - self.0.abort(); - } -} - -impl Deref for AutoAbortJoinHandle { - type Target = task::JoinHandle; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for AutoAbortJoinHandle { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl Future for AutoAbortJoinHandle { - type Output = Result; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - Pin::new(&mut Pin::into_inner(self).0).poll(cx) - } -} diff --git a/src/helpers/auto_abort_join_handle.rs b/src/helpers/auto_abort_join_handle.rs new file mode 100644 index 00000000..fa476a8b --- /dev/null +++ b/src/helpers/auto_abort_join_handle.rs @@ -0,0 +1,45 @@ +use std::{ + future::Future, + ops::{Deref, DerefMut}, + pin::Pin, + task::{Context, Poll}, +}; + +use tokio::task::{JoinError, JoinHandle}; + +#[derive(Debug)] +pub struct AutoAbortJoinHandle(JoinHandle); + +impl AutoAbortJoinHandle { + pub fn new(handle: JoinHandle) -> Self { + Self(handle) + } +} + +impl Drop for AutoAbortJoinHandle { + fn drop(&mut self) { + self.0.abort(); + } +} + +impl Deref for AutoAbortJoinHandle { + type Target = JoinHandle; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for AutoAbortJoinHandle { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl Future for AutoAbortJoinHandle { + type Output = Result; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + Pin::new(&mut Pin::into_inner(self).0).poll(cx) + } +}