diff options
author | Simon Garrelou <simon.garrelou@gmail.com> | 2023-07-07 17:00:29 +0200 |
---|---|---|
committer | Simon Garrelou <simon.garrelou@gmail.com> | 2023-07-07 17:00:29 +0200 |
commit | 12e14bc1f35137864840433e36b66b219a818371 (patch) | |
tree | 7efdab53201ebb202d98e405b7339da0ea0bbee7 | |
parent | 377bfd98cea99483eda2d659d8f1423761ea25ed (diff) | |
download | rss-12e14bc1f35137864840433e36b66b219a818371.tar.gz rss-12e14bc1f35137864840433e36b66b219a818371.zip |
Use blocking reqwest
-rw-r--r-- | Cargo.lock | 22 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/fetch.rs | 8 | ||||
-rw-r--r-- | src/main.rs | 9 |
4 files changed, 16 insertions, 26 deletions
@@ -460,6 +460,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
460 | checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" | 460 | checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" |
461 | 461 | ||
462 | [[package]] | 462 | [[package]] |
463 | name = "futures-io" | ||
464 | version = "0.3.28" | ||
465 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
466 | checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" | ||
467 | |||
468 | [[package]] | ||
463 | name = "futures-sink" | 469 | name = "futures-sink" |
464 | version = "0.3.28" | 470 | version = "0.3.28" |
465 | source = "registry+https://github.com/rust-lang/crates.io-index" | 471 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -478,9 +484,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
478 | checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" | 484 | checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" |
479 | dependencies = [ | 485 | dependencies = [ |
480 | "futures-core", | 486 | "futures-core", |
487 | "futures-io", | ||
481 | "futures-task", | 488 | "futures-task", |
489 | "memchr", | ||
482 | "pin-project-lite", | 490 | "pin-project-lite", |
483 | "pin-utils", | 491 | "pin-utils", |
492 | "slab", | ||
484 | ] | 493 | ] |
485 | 494 | ||
486 | [[package]] | 495 | [[package]] |
@@ -1173,7 +1182,6 @@ dependencies = [ | |||
1173 | "reqwest", | 1182 | "reqwest", |
1174 | "rss 2.0.4", | 1183 | "rss 2.0.4", |
1175 | "tera", | 1184 | "tera", |
1176 | "tokio", | ||
1177 | ] | 1185 | ] |
1178 | 1186 | ||
1179 | [[package]] | 1187 | [[package]] |
@@ -1471,22 +1479,10 @@ dependencies = [ | |||
1471 | "num_cpus", | 1479 | "num_cpus", |
1472 | "pin-project-lite", | 1480 | "pin-project-lite", |
1473 | "socket2", | 1481 | "socket2", |
1474 | "tokio-macros", | ||
1475 | "windows-sys 0.48.0", | 1482 | "windows-sys 0.48.0", |
1476 | ] | 1483 | ] |
1477 | 1484 | ||
1478 | [[package]] | 1485 | [[package]] |
1479 | name = "tokio-macros" | ||
1480 | version = "2.1.0" | ||
1481 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1482 | checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" | ||
1483 | dependencies = [ | ||
1484 | "proc-macro2", | ||
1485 | "quote", | ||
1486 | "syn 2.0.18", | ||
1487 | ] | ||
1488 | |||
1489 | [[package]] | ||
1490 | name = "tokio-native-tls" | 1486 | name = "tokio-native-tls" |
1491 | version = "0.3.1" | 1487 | version = "0.3.1" |
1492 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1488 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -11,7 +11,6 @@ anyhow = "1.0.71" | |||
11 | chrono = "0.4.26" | 11 | chrono = "0.4.26" |
12 | clap = { version = "4.3.4", features = ["derive"] } | 12 | clap = { version = "4.3.4", features = ["derive"] } |
13 | regex = "1.8.4" | 13 | regex = "1.8.4" |
14 | reqwest = "0.11.18" | 14 | reqwest = { version = "0.11.18", features = ["blocking"] } |
15 | rss = { version = "2.0.4", features = ["serde"] } | 15 | rss = { version = "2.0.4", features = ["serde"] } |
16 | tera = "1.19.0" | 16 | tera = "1.19.0" |
17 | tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] } | ||
diff --git a/src/fetch.rs b/src/fetch.rs index 3d619c1..83388b8 100644 --- a/src/fetch.rs +++ b/src/fetch.rs | |||
@@ -1,11 +1,9 @@ | |||
1 | use anyhow::Result; | 1 | use anyhow::Result; |
2 | use rss::Channel; | 2 | use rss::Channel; |
3 | 3 | ||
4 | pub async fn run(url: String) -> Result<Channel> { | 4 | pub fn run(url: String) -> Result<Channel> { |
5 | let content = reqwest::get(url) | 5 | let content = reqwest::blocking::get(url)? |
6 | .await? | 6 | .bytes()?; |
7 | .bytes() | ||
8 | .await?; | ||
9 | 7 | ||
10 | let channel = Channel::read_from(&content[..])?; | 8 | let channel = Channel::read_from(&content[..])?; |
11 | Ok(channel) | 9 | Ok(channel) |
diff --git a/src/main.rs b/src/main.rs index 7fa00f7..406eff1 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | use clap::{Subcommand, Parser, ValueEnum}; | 1 | use clap::{Subcommand, Parser, ValueEnum}; |
2 | use rss::Channel; | 2 | use rss::Channel; |
3 | use tokio; | 3 | use std::process::exit; |
4 | use std::{process::exit, io::Write}; | ||
5 | 4 | ||
6 | mod fetch; | 5 | mod fetch; |
7 | mod sort; | 6 | mod sort; |
@@ -71,14 +70,12 @@ pub enum Order { | |||
71 | Asc, | 70 | Asc, |
72 | Desc | 71 | Desc |
73 | } | 72 | } |
74 | 73 | fn main() { | |
75 | #[tokio::main] | ||
76 | async fn main() { | ||
77 | let args = Args::parse(); | 74 | let args = Args::parse(); |
78 | 75 | ||
79 | match args.command { | 76 | match args.command { |
80 | Commands::Fetch { url } => { | 77 | Commands::Fetch { url } => { |
81 | match fetch::run(url).await { | 78 | match fetch::run(url) { |
82 | Ok(c) => { | 79 | Ok(c) => { |
83 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); | 80 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); |
84 | }, | 81 | }, |