best practice for own main() function #2433
Unanswered
LuckyTurtleDev
asked this question in
Questions
Replies: 1 comment 2 replies
-
I think you are looking for something like the fairly new Check the examples here: 46c441a Note: this is far from a "suggested use", see the comment by @SergioBenitez starting with Another useful trick: you should be able to put the launch / main macros on a function in a submodule. This way the generated I hope one of these solutions helps you a bit |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The doc of rocket suggest to use the
#[launch]
or#[main]
. This is regular fine.But if you want to do some stuff before the async runtime has started. This is not possible with this.
I have run
cargo-expand
to get a idea, what the macro is doing.It does call
.launch()
on the created rocket builder andawait
this future.It looks like the async runtime is initialed with
::rocket::async_main
, but I can not find any documentation about it.What is the best practice for own
main()
function?my expanded code:
my new written code with own main:
I did get a warning, that I must use Rocket.
I am not sure why I must use the result. The expanded macro does only assign it to _res and never use it again.
Maybe something like
#[tokio::main]
for rocket would be nice.This would allow the user to define a function as entrypoint for rocket, but would still allow to have a own main function.
Somethink like:
Beta Was this translation helpful? Give feedback.
All reactions