From f830671ee9bf84d0d2e21fb0aef6c45fd7f3159f Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Fri, 30 Dec 2022 09:59:39 -0500 Subject: [PATCH] Make tokio's rt-multi-thread enabled again in examples --- Cargo.toml | 3 ++- examples/follow_profile.rs | 17 ++++++++++++++--- examples/follows_me.rs | 15 +++++++++++++-- examples/get_statuses.rs | 15 +++++++++++++-- examples/home_timeline.rs | 15 +++++++++++++-- examples/log_events.rs | 15 +++++++++++++-- examples/post_status.rs | 15 +++++++++++++-- examples/print_your_profile.rs | 15 +++++++++++++-- examples/register/mod.rs | 10 +++++++++- examples/search.rs | 15 +++++++++++++-- examples/upload_photo.rs | 15 +++++++++++++-- 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,13 +10,21 @@ 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?; Ok(()) } +#[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 { 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!(