summaryrefslogtreecommitdiffstats
path: root/examples/download_progress/src/download.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-11-22 02:14:33 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-11-22 02:14:56 +0100
commit6ccc828607b22a0583c12bad638ee2bc7e7310b8 (patch)
tree93348c305dd8cb62a775f1e47001724739e4b712 /examples/download_progress/src/download.rs
parent53b7f507f8e411c9911c1b8d1b75a3e49f7a4ec3 (diff)
downloadiced-6ccc828607b22a0583c12bad638ee2bc7e7310b8.tar.gz
iced-6ccc828607b22a0583c12bad638ee2bc7e7310b8.tar.bz2
iced-6ccc828607b22a0583c12bad638ee2bc7e7310b8.zip
Use `Task::run` in `download_progress` example
Diffstat (limited to 'examples/download_progress/src/download.rs')
-rw-r--r--examples/download_progress/src/download.rs19
1 files changed, 4 insertions, 15 deletions
diff --git a/examples/download_progress/src/download.rs b/examples/download_progress/src/download.rs
index a8e7b404..d63fb906 100644
--- a/examples/download_progress/src/download.rs
+++ b/examples/download_progress/src/download.rs
@@ -1,24 +1,13 @@
use iced::futures::{SinkExt, Stream, StreamExt};
use iced::stream::try_channel;
-use iced::Subscription;
-use std::hash::Hash;
use std::sync::Arc;
-// Just a little utility function
-pub fn file<I: 'static + Hash + Copy + Send + Sync, T: ToString>(
- id: I,
- url: T,
-) -> iced::Subscription<(I, Result<Progress, Error>)> {
- Subscription::run_with_id(
- id,
- download(url.to_string()).map(move |progress| (id, progress)),
- )
-}
-
-fn download(url: String) -> impl Stream<Item = Result<Progress, Error>> {
+pub fn download(
+ url: impl AsRef<str>,
+) -> impl Stream<Item = Result<Progress, Error>> {
try_channel(1, move |mut output| async move {
- let response = reqwest::get(&url).await?;
+ let response = reqwest::get(url.as_ref()).await?;
let total = response.content_length().ok_or(Error::NoContentLength)?;
let _ = output.send(Progress::Downloading { percent: 0.0 }).await;