Don't define async fn run()

rustc now emits enough good compiler error messages for procedural macros such as `#[tokio::main]`.
This commit is contained in:
Hirrolot 2021-12-27 21:13:46 +06:00
parent b10288f751
commit b253b7eec2
11 changed files with 30 additions and 95 deletions

View file

@ -342,31 +342,6 @@ async fn handle_message(
[More examples!](./examples)
## Recommendations
- Use this pattern:
```rust
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
// Your logic here...
}
```
Instead of this:
```rust
#[tokio::main]
async fn main() {
// Your logic here...
}
```
The second one produces very strange compiler messages due to the `#[tokio::main]` macro. However, the examples in this README use the second variant for brevity.
## FAQ
**Q: Where I can ask questions?**

View file

@ -155,10 +155,6 @@ async fn action(
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
teloxide::enable_logging!();
log::info!("Starting admin_bot...");

View file

@ -27,10 +27,6 @@ use teloxide::prelude::*;
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
teloxide::enable_logging!();
log::info!("Starting dialogue_bot...");

View file

@ -7,10 +7,6 @@ type TeleBot = AutoSend<Bot>;
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
teloxide::enable_logging!();
log::info!("Starting dices_bot...");

View file

@ -19,7 +19,21 @@ use reqwest::{StatusCode, Url};
#[tokio::main]
async fn main() {
run().await;
teloxide::enable_logging!();
log::info!("Starting heroku_ping_pong_bot...");
let bot = Bot::from_env().auto_send();
let cloned_bot = bot.clone();
teloxide::repl_with_listener(
bot,
|message| async move {
message.answer("pong").await?;
respond(())
},
webhook(cloned_bot).await,
)
.await;
}
async fn handle_rejection(error: warp::Rejection) -> Result<impl warp::Reply, Infallible> {
@ -75,21 +89,3 @@ pub async fn webhook(bot: AutoSend<Bot>) -> impl update_listeners::UpdateListene
state.1.clone()
})
}
async fn run() {
teloxide::enable_logging!();
log::info!("Starting heroku_ping_pong_bot...");
let bot = Bot::from_env().auto_send();
let cloned_bot = bot.clone();
teloxide::repl_with_listener(
bot,
|message| async move {
message.answer("pong").await?;
respond(())
},
webhook(cloned_bot).await,
)
.await;
}

View file

@ -9,10 +9,6 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
let bot = Bot::from_env().auto_send();
// Create a new dispatcher to handle incoming queries
Dispatcher::new(bot)

View file

@ -19,7 +19,21 @@ use reqwest::{StatusCode, Url};
#[tokio::main]
async fn main() {
run().await;
teloxide::enable_logging!();
log::info!("Starting ngrok_ping_pong_bot...");
let bot = Bot::from_env().auto_send();
let cloned_bot = bot.clone();
teloxide::repl_with_listener(
bot,
|message| async move {
message.answer("pong").await?;
respond(())
},
webhook(cloned_bot).await,
)
.await;
}
async fn handle_rejection(error: warp::Rejection) -> Result<impl warp::Reply, Infallible> {
@ -67,21 +81,3 @@ pub async fn webhook(bot: AutoSend<Bot>) -> impl update_listeners::UpdateListene
state.1.clone()
})
}
async fn run() {
teloxide::enable_logging!();
log::info!("Starting ngrok_ping_pong_bot...");
let bot = Bot::from_env().auto_send();
let cloned_bot = bot.clone();
teloxide::repl_with_listener(
bot,
|message| async move {
message.answer("pong").await?;
respond(())
},
webhook(cloned_bot).await,
)
.await;
}

View file

@ -27,10 +27,6 @@ type In = DialogueWithCx<AutoSend<Bot>, Message, Dialogue, StorageError>;
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
let bot = Bot::from_env().auto_send();
Dispatcher::new(bot)
.messages_handler(DialogueDispatcher::with_storage(

View file

@ -12,10 +12,6 @@ lazy_static! {
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
teloxide::enable_logging!();
log::info!("Starting shared_state_bot...");

View file

@ -37,10 +37,6 @@ async fn answer(
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
teloxide::enable_logging!();
log::info!("Starting simple_commands_bot...");

View file

@ -80,10 +80,6 @@
//!
//! #[tokio::main]
//! async fn main() {
//! run().await;
//! }
//!
//! async fn run() {
//! teloxide::enable_logging!();
//! log::info!("Starting dialogue_bot!");
//!