最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Rust Teloxide thread 'main' has overflowed its stack - Stack Overflow

programmeradmin2浏览0评论

When running the following in debug mode, I always receive an error:

thread 'main' has overflowed its stack

I'm using Windows and the code works with cargo run --release. Is there any fix for this problem other than always running in release mode?

handlers.rs

use teloxide::prelude::*;
use teloxide::types::{CallbackQuery, Message};

use crate::telegram::menus;

pub async fn start(bot: Bot, message: Message) -> ResponseResult<()> {
    bot.send_message(message.chat.id, "Hauptmenü:")
        .reply_markup(menus::main_menu())
        .await?;
    Ok(())
}

pub async fn handle_callback(bot: Bot, query: CallbackQuery) -> ResponseResult<()> {
    if let Some(data) = query.data {
        match data.as_str() {
            "submenu" => {
                if let Some(msg) = query.message {
                    bot.edit_message_reply_markup(msg.chat().id, msg.id())
                        .reply_markup(menus::submenu())
                        .await?;
                }
            }
            "back_to_main" => {
                if let Some(msg) = query.message {
                    bot.edit_message_reply_markup(msg.chat().id, msg.id())
                        .reply_markup(menus::main_menu())
                        .await?;
                }
            }
            other => {
                // Für alle anderen Buttons einfach eine Bestätigung senden.
                bot.answer_callback_query(query.id)
                    .text(format!("You selected: {}", other))
                    .await?;
            }
        }
    }
    Ok(())
}

menus.rs

use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup};

pub fn main_menu() -> InlineKeyboardMarkup {
    InlineKeyboardMarkup::new(vec![
        vec![InlineKeyboardButton::callback("Option 1", "opt1")],
        vec![InlineKeyboardButton::callback("Option 2", "opt2")],
        vec![InlineKeyboardButton::callback("Submenu", "submenu")],
    ])
}

pub fn submenu() -> InlineKeyboardMarkup {
    InlineKeyboardMarkup::new(vec![
        vec![InlineKeyboardButton::callback("Sub Option 1", "subopt1")],
        vec![InlineKeyboardButton::callback("Sub Option 2", "subopt2")],
        vec![InlineKeyboardButton::callback("Sub Option 3", "subopt3")],
        vec![InlineKeyboardButton::callback("Back", "back_to_main")],
    ])
}

main.rs

use teloxide::prelude::*;
use teloxide::dptree;

mod config;
mod telegram;

use config::Settings;
use telegram::handlers::{start, handle_callback};

#[tokio::main]
async fn main() {
    pretty_env_logger::init();
    log::info!("Starting bot...");

    let settings = Settings::new().expect("Failed to load config");
    let bot = Bot::new(settings.telegram_token);

    let handler = dptree::entry()
        .branch(Update::filter_message().endpoint(start))
        .branch(Update::filter_callback_query().endpoint(handle_callback));

    Dispatcher::builder(bot, handler)
        .enable_ctrlc_handler()
        .build()
        .dispatch()
        .await;
}
发布评论

评论列表(0)

  1. 暂无评论