Make tokio's rt-multi-thread enabled again in examples

This commit is contained in:
D. Scott Boggs 2022-12-30 09:59:39 -05:00 committed by Scott Boggs
parent 6ba0cd03f8
commit f830671ee9
11 changed files with 129 additions and 21 deletions

View File

@ -64,7 +64,7 @@ optional = true
[dependencies.tokio] [dependencies.tokio]
version = "1.22.0" version = "1.22.0"
features = ["macros"] features = ["macros", "io-util", "time"]
[dependencies.tokio-util] [dependencies.tokio-util]
version = "0.7.4" version = "0.7.4"
@ -91,5 +91,6 @@ all = ["toml", "json", "env"]
# default = ["reqwest/default-tls"] # default = ["reqwest/default-tls"]
default = ["reqwest/default-tls"] default = ["reqwest/default-tls"]
env = ["envy"] env = ["envy"]
mt = ["tokio/rt-multi-thread"]
json = [] json = []
rustls-tls = ["reqwest/rustls-tls"] rustls-tls = ["reqwest/rustls-tls"]

View File

@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result; use mastodon_async::Result;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
let mastodon = register::get_mastodon_data().await?; let mastodon = register::get_mastodon_data().await?;
let input = register::read_line("Enter the account id you'd like to follow: ")?; let input = register::read_line("Enter the account id you'd like to follow: ")?;
let new_follow = mastodon.follow(input.trim()).await?; let new_follow = mastodon.follow(input.trim()).await?;
@ -14,10 +13,22 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(
"examples require the `toml` feature, run this command for this example:\n\ncargo run \ "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"
); );
} }

View File

@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result; use mastodon_async::Result;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
use futures::StreamExt; use futures::StreamExt;
let mastodon = register::get_mastodon_data().await?; let mastodon = register::get_mastodon_data().await?;
@ -21,6 +20,18 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(

View File

@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result; use mastodon_async::Result;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
use futures_util::StreamExt; use futures_util::StreamExt;
use mastodon_async::StatusesRequest; use mastodon_async::StatusesRequest;
@ -23,6 +22,18 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(

View File

@ -5,8 +5,7 @@ use futures_util::StreamExt;
use mastodon_async::Result; use mastodon_async::Result;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
register::get_mastodon_data() register::get_mastodon_data()
.await? .await?
.get_home_timeline() .get_home_timeline()
@ -25,6 +24,18 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(

View File

@ -7,8 +7,7 @@ use log::{as_serde, info};
use mastodon_async::Result; use mastodon_async::Result;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
use log::warn; use log::warn;
femme::with_level(log::LevelFilter::Info); femme::with_level(log::LevelFilter::Info);
@ -27,6 +26,18 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(

View File

@ -5,8 +5,7 @@ mod register;
use mastodon_async::{Language, Result, StatusBuilder, Visibility}; use mastodon_async::{Language, Result, StatusBuilder, Visibility};
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
let mastodon = register::get_mastodon_data().await?; let mastodon = register::get_mastodon_data().await?;
let status = StatusBuilder::new() let status = StatusBuilder::new()
.status(register::read_line( .status(register::read_line(
@ -34,6 +33,18 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(

View File

@ -5,8 +5,7 @@ mod register;
use mastodon_async::Result; use mastodon_async::Result;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
let mastodon = register::get_mastodon_data().await?; let mastodon = register::get_mastodon_data().await?;
let you = mastodon.verify_credentials().await?; let you = mastodon.verify_credentials().await?;
@ -15,6 +14,18 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(

View File

@ -10,13 +10,21 @@ use mastodon_async::helpers::toml;
use mastodon_async::{helpers::cli, Result}; use mastodon_async::{helpers::cli, Result};
#[allow(dead_code)] #[allow(dead_code)]
#[cfg(feature = "toml")] #[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
register().await?; register().await?;
Ok(()) 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)] #[allow(dead_code)]
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
pub async fn get_mastodon_data() -> Result<Mastodon> { pub async fn get_mastodon_data() -> Result<Mastodon> {

View File

@ -5,8 +5,7 @@ mod register;
use mastodon_async::Result; use mastodon_async::Result;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
let mastodon = register::get_mastodon_data().await?; let mastodon = register::get_mastodon_data().await?;
let input = register::read_line("Enter the term you'd like to search: ")?; let input = register::read_line("Enter the term you'd like to search: ")?;
let result = mastodon.search(&input, false).await?; let result = mastodon.search(&input, false).await?;
@ -16,6 +15,18 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(

View File

@ -4,8 +4,7 @@ mod register;
use mastodon_async::{Result, StatusBuilder, Visibility}; use mastodon_async::{Result, StatusBuilder, Visibility};
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[tokio::main] async fn run() -> Result<()> {
async fn main() -> Result<()> {
use register::bool_input; use register::bool_input;
femme::with_level(femme::LevelFilter::Trace); femme::with_level(femme::LevelFilter::Trace);
let mastodon = register::get_mastodon_data().await?; let mastodon = register::get_mastodon_data().await?;
@ -33,6 +32,18 @@ async fn main() -> Result<()> {
Ok(()) 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"))] #[cfg(not(feature = "toml"))]
fn main() { fn main() {
println!( println!(