summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorD. Scott Boggs <scott@tams.tech>2022-12-30 09:59:39 -0500
committerD. Scott Boggs <scott@tams.tech>2022-12-30 10:03:13 -0500
commit75d413ca88369e7b5f2ffdd707d12c9bec9710af (patch)
tree7b54ac9b96864c6c3bee53e428310155eea977ae
parent6ba0cd03f81eb9fdc00199220b4925c007f0a32f (diff)
Make tokio's rt-multi-thread enabled again in examplesfix/breakages-from-tokio-dependency-change
-rw-r--r--Cargo.toml3
-rw-r--r--examples/follow_profile.rs17
-rw-r--r--examples/follows_me.rs15
-rw-r--r--examples/get_statuses.rs15
-rw-r--r--examples/home_timeline.rs15
-rw-r--r--examples/log_events.rs15
-rw-r--r--examples/post_status.rs15
-rw-r--r--examples/print_your_profile.rs15
-rw-r--r--examples/register/mod.rs10
-rw-r--r--examples/search.rs15
-rw-r--r--examples/upload_photo.rs15
11 files changed, 129 insertions, 21 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 200363e..00a6c57 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -64,7 +64,7 @@ optional = true
[dependencies.tokio]
version = "1.22.0"
-features = ["macros"]
+features = ["macros", "io-util", "time"]
[dependencies.tokio-util]
version = "0.7.4"
@@ -91,5 +91,6 @@ all = ["toml", "json", "env"]
# default = ["reqwest/default-tls"]
default = ["reqwest/default-tls"]
env = ["envy"]
+mt = ["tokio/rt-multi-thread"]
json = []
rustls-tls = ["reqwest/rustls-tls"]
diff --git a/examples/follow_profile.rs b/examples/follow_profile.rs
index 57e8f9d..103d703 100644
--- a/examples/follow_profile.rs
+++ b/examples/follow_profile.rs
@@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result;
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
let mastodon = register::get_mastodon_data().await?;
let input = register::read_line("Enter the account id you'd like to follow: ")?;
let new_follow = mastodon.follow(input.trim()).await?;
@@ -14,10 +13,22 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(
"examples require the `toml` feature, run this command for this example:\n\ncargo run \
- --example follow_profile --features toml\n"
+ --example follow_profile --features toml,mt\n"
);
}
diff --git a/examples/follows_me.rs b/examples/follows_me.rs
index 57c4463..4b5c6c3 100644
--- a/examples/follows_me.rs
+++ b/examples/follows_me.rs
@@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result;
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
use futures::StreamExt;
let mastodon = register::get_mastodon_data().await?;
@@ -21,6 +20,18 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(
diff --git a/examples/get_statuses.rs b/examples/get_statuses.rs
index 916fd44..f83fcba 100644
--- a/examples/get_statuses.rs
+++ b/examples/get_statuses.rs
@@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result;
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
use futures_util::StreamExt;
use mastodon_async::StatusesRequest;
@@ -23,6 +22,18 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(
diff --git a/examples/home_timeline.rs b/examples/home_timeline.rs
index c97bf48..621054c 100644
--- a/examples/home_timeline.rs
+++ b/examples/home_timeline.rs
@@ -5,8 +5,7 @@ use futures_util::StreamExt;
use mastodon_async::Result;
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
register::get_mastodon_data()
.await?
.get_home_timeline()
@@ -25,6 +24,18 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(
diff --git a/examples/log_events.rs b/examples/log_events.rs
index 48d3b32..3dd8a80 100644
--- a/examples/log_events.rs
+++ b/examples/log_events.rs
@@ -7,8 +7,7 @@ use log::{as_serde, info};
use mastodon_async::Result;
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
use log::warn;
femme::with_level(log::LevelFilter::Info);
@@ -27,6 +26,18 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(
diff --git a/examples/post_status.rs b/examples/post_status.rs
index 43e1b28..2b0379f 100644
--- a/examples/post_status.rs
+++ b/examples/post_status.rs
@@ -5,8 +5,7 @@ mod register;
use mastodon_async::{Language, Result, StatusBuilder, Visibility};
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
let mastodon = register::get_mastodon_data().await?;
let status = StatusBuilder::new()
.status(register::read_line(
@@ -34,6 +33,18 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(
diff --git a/examples/print_your_profile.rs b/examples/print_your_profile.rs
index 30ae355..bd73dcc 100644
--- a/examples/print_your_profile.rs
+++ b/examples/print_your_profile.rs
@@ -5,8 +5,7 @@ mod register;
use mastodon_async::Result;
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
let mastodon = register::get_mastodon_data().await?;
let you = mastodon.verify_credentials().await?;
@@ -15,6 +14,18 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(
diff --git a/examples/register/mod.rs b/examples/register/mod.rs
index 9c881e5..eb86b7b 100644
--- a/examples/register/mod.rs
+++ b/examples/register/mod.rs
@@ -10,7 +10,7 @@ use mastodon_async::helpers::toml;
use mastodon_async::{helpers::cli, Result};
#[allow(dead_code)]
-#[cfg(feature = "toml")]
+#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
register().await?;
@@ -18,6 +18,14 @@ async fn main() -> Result<()> {
}
#[allow(dead_code)]
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ register().await?;
+ Ok(())
+}
+
+#[allow(dead_code)]
#[cfg(feature = "toml")]
pub async fn get_mastodon_data() -> Result<Mastodon> {
if let Ok(data) = toml::from_file("mastodon-data.toml") {
diff --git a/examples/search.rs b/examples/search.rs
index c6fd8d0..bed6523 100644
--- a/examples/search.rs
+++ b/examples/search.rs
@@ -5,8 +5,7 @@ mod register;
use mastodon_async::Result;
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
let mastodon = register::get_mastodon_data().await?;
let input = register::read_line("Enter the term you'd like to search: ")?;
let result = mastodon.search(&input, false).await?;
@@ -16,6 +15,18 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(
diff --git a/examples/upload_photo.rs b/examples/upload_photo.rs
index ddd2de6..4492945 100644
--- a/examples/upload_photo.rs
+++ b/examples/upload_photo.rs
@@ -4,8 +4,7 @@ mod register;
use mastodon_async::{Result, StatusBuilder, Visibility};
#[cfg(feature = "toml")]
-#[tokio::main]
-async fn main() -> Result<()> {
+async fn run() -> Result<()> {
use register::bool_input;
femme::with_level(femme::LevelFilter::Trace);
let mastodon = register::get_mastodon_data().await?;
@@ -33,6 +32,18 @@ async fn main() -> Result<()> {
Ok(())
}
+#[cfg(all(feature = "toml", feature = "mt"))]
+#[tokio::main]
+async fn main() -> Result<()> {
+ run().await
+}
+
+#[cfg(all(feature = "toml", not(feature = "mt")))]
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> Result<()> {
+ run().await
+}
+
#[cfg(not(feature = "toml"))]
fn main() {
println!(