Skip to content

Commit c550480

Browse files
downloader: Accept Url's directly instead of parsing them
1 parent 987beaa commit c550480

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/downloader/manager.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,17 @@ impl DownloadManager {
4242
manager
4343
}
4444

45-
pub fn download(
46-
&self,
47-
url: impl TryInto<Url>,
48-
destination: impl AsRef<Path>,
49-
) -> Result<DownloadBuilder, Error> {
50-
let url = url
51-
.try_into()
52-
.map_err(|_| Error::Download(DownloadError::InvalidUrl))?;
53-
Ok(DownloadBuilder::new(self, url, destination))
45+
pub fn download(&self, url: Url, destination: impl AsRef<Path>) -> DownloadBuilder {
46+
DownloadBuilder::new(self, url, destination)
5447
}
5548

5649
pub fn download_with_config(
5750
&self,
5851
url: Url,
5952
destination: impl AsRef<Path>,
6053
config: DownloadConfig,
61-
) -> Result<DownloadBuilder, Error> {
62-
self.download(url, destination)
63-
.map(|builder| builder.with_config(config))
54+
) -> DownloadBuilder {
55+
self.download(url, destination).with_config(config)
6456
}
6557

6658
pub async fn set_max_parallel_downloads(&self, limit: usize) -> Result<(), Error> {

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pub enum DownloadError {
2727
ManagerShutdown,
2828
#[error("File already exists: {path}")]
2929
FileExists { path: PathBuf },
30-
#[error("Invalid URL")]
31-
InvalidUrl,
30+
#[error("Invalid URL: {0}")]
31+
InvalidUrl(#[from] url::ParseError),
3232
}

0 commit comments

Comments
 (0)