火箭发射和主入口点有什么区别

发布于 2025-02-05 08:04:33 字数 393 浏览 4 评论 0原文

我正在使用Rust Rocket Rocket = {version =“ = 0.5.5.0-rc.2”,功能= [“ JSON”]}作为我的Web服务器,今天我发现有两种启动的方法火箭是这样的开始之一:

#[rocket::main]
async fn main() {
    // the rocket start logic
}

另一种方式看起来像这样:

#[launch]
async fn rocket() -> _ {
    // the rocket start logic
}

我应该使用哪种样式?哪一个更好?我应该从两个启动风格中学到什么?我是从Google搜索的,但没有人谈论这个。

I am using rust rocket rocket = { version = "=0.5.0-rc.2", features = ["json"] } as my web server, today I found there is two way to start the rocket, one of the start like this:

#[rocket::main]
async fn main() {
    // the rocket start logic
}

the other way look like this:

#[launch]
async fn rocket() -> _ {
    // the rocket start logic
}

which one style should I use? which one is better? what should I learn from the two startup style? I am search from google but no one talk about this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杀手六號 2025-02-12 08:04:33

documentation ####### [Rocket :: Main]

应仅在检查IGNITE()或启动()的返回值

时使用

在使用 rust-分析仪 #[Rocket :: Main]可靠地发现是带来附加优势的主要功能,方便 debug run 按钮在功能上方显示。

但是,对于生产,建议使用#[启动]属性。

As stated in the documentation, #[rocket::main]

should be used only when the return values of ignite() or launch() are to be inspected

If you use rust-analyzer #[rocket::main] is reliably discovered as the main function which brings the added benefit, that convenient Debug and Run buttons are displayed above the function.

For production it would however be recommended to use the #[launch] attribute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文