Skip to content

why is there a restriction of fn main() on #[async_std::main]? #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shakyShane opened this issue Aug 2, 2020 · 2 comments
Closed

Comments

@shakyShane
Copy link
Contributor

More of a question really as this was surprising to me.

When using Tokio, you can add #[tokio::main] to any fn and it works as expected, expanding out to eventually calling block_on on a runtime.

I can see https://github.com/async-rs/async-attributes/blob/master/src/lib.rs#L59 and wondered why this restriction is in place? if there's no technical limitation I will happily send a PR 👍

Also whilst here, I noticed that since you expect the attribute to always exist on main, your code doesn't account for visibilty modifiers, eg: pub fn main() would lose the pub

again, if it's just yet to be built then I'd love to help out.

Many thanks for your time.

@yoshuawuyts
Copy link
Collaborator

We made async fn main only work with main because that's what it's intended to be used for. If someone's using it somewhere else we figured that would probably be a bug.

However we should indeed retain any visibility modifiers, and the fact that we don't is a bug. If you'd like to send in a PR for that it'd be much appreciated!

@shakyShane
Copy link
Contributor Author

shakyShane commented Aug 4, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants