Skip to content

Commit fb572dd

Browse files
djcrami3l
authored andcommitted
download: simplify feature guards
1 parent d06af1b commit fb572dd

File tree

2 files changed

+14
-43
lines changed

2 files changed

+14
-43
lines changed

download/src/lib.rs

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ const REQWEST_RUSTLS_TLS_USER_AGENT: &str =
2626

2727
#[derive(Debug, Copy, Clone)]
2828
pub enum Backend {
29+
#[cfg(feature = "curl-backend")]
2930
Curl,
31+
#[cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-native-tls"))]
3032
Reqwest(TlsBackend),
3133
}
3234

@@ -140,14 +142,24 @@ impl Backend {
140142
Ok::<(), anyhow::Error>(())
141143
}
142144

145+
#[cfg_attr(
146+
all(
147+
not(feature = "curl-backend"),
148+
not(feature = "reqwest-rustls-tls"),
149+
not(feature = "reqwest-native-tls")
150+
),
151+
allow(unused_variables)
152+
)]
143153
async fn download(
144154
self,
145155
url: &Url,
146156
resume_from: u64,
147157
callback: DownloadCallback<'_>,
148158
) -> Result<()> {
149159
match self {
160+
#[cfg(feature = "curl-backend")]
150161
Self::Curl => curl::download(url, resume_from, callback),
162+
#[cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-native-tls"))]
151163
Self::Reqwest(tls) => reqwest_be::download(url, resume_from, callback, tls).await,
152164
}
153165
}
@@ -170,13 +182,6 @@ pub enum Event<'a> {
170182

171183
type DownloadCallback<'a> = &'a dyn Fn(Event<'_>) -> Result<()>;
172184

173-
#[cfg(all(
174-
not(feature = "reqwest-rustls-tls"),
175-
not(feature = "reqwest-native-tls"),
176-
not(feature = "curl-backend")
177-
))]
178-
compile_error!("Must enable at least one backend");
179-
180185
/// Download via libcurl; encrypt with the native (or OpenSSl) TLS
181186
/// stack via libcurl
182187
#[cfg(feature = "curl-backend")]
@@ -494,39 +499,3 @@ pub enum DownloadError {
494499
#[error(transparent)]
495500
CurlError(#[from] ::curl::Error),
496501
}
497-
498-
#[cfg(not(feature = "curl-backend"))]
499-
pub mod curl {
500-
use anyhow::{anyhow, Result};
501-
use url::Url;
502-
503-
use super::{DownloadError, Event};
504-
505-
pub fn download(
506-
_url: &Url,
507-
_resume_from: u64,
508-
_callback: &dyn Fn(Event<'_>) -> Result<()>,
509-
) -> Result<()> {
510-
Err(anyhow!(DownloadError::BackendUnavailable("curl")))
511-
}
512-
}
513-
514-
#[cfg(all(
515-
not(feature = "reqwest-rustls-tls"),
516-
not(feature = "reqwest-native-tls")
517-
))]
518-
pub mod reqwest_be {
519-
use anyhow::{anyhow, Result};
520-
use url::Url;
521-
522-
use super::{DownloadError, Event, TlsBackend};
523-
524-
pub async fn download(
525-
_url: &Url,
526-
_resume_from: u64,
527-
_callback: &dyn Fn(Event<'_>) -> Result<()>,
528-
_tls: TlsBackend,
529-
) -> Result<()> {
530-
Err(anyhow!(DownloadError::BackendUnavailable("reqwest")))
531-
}
532-
}

src/utils/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ async fn download_file_(
305305
};
306306

307307
notify_handler(match backend {
308+
#[cfg(feature = "curl-backend")]
308309
Backend::Curl => Notification::UsingCurl,
310+
#[cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-native-tls"))]
309311
Backend::Reqwest(_) => Notification::UsingReqwest,
310312
});
311313

0 commit comments

Comments
 (0)