Skip to content
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

Create Macro to allow async fn main() #104

Closed
wants to merge 10 commits into from

Conversation

torfmaster
Copy link
Collaborator

merge after #103

Content of the PR

In this PR we add a proc macro attribute to allow creation of a async fn main() instead of a synchronous fn main(). The advantage of this macro that the boilerplate code to create an async main function may be subject to breaking changes.

Miscellaneous Changes

To simplify usage of the library all crates have been added to a workspace and the CI now also runs tests for the other crates in this repository.

Usage

For an example see the example async.rs.

@jrvanwhy
Copy link
Collaborator

Why did you choose to use a procedural macro rather than implementing lang_items::Termination for T: Future<Output = ()>?

@torfmaster
Copy link
Collaborator Author

I have no detailled knowledge about the Termination trait but I see two obstacles here:

  • Termination is only available in std as far as I can judge
  • the trait is unstable and I at least I would try to not enable yet another nightly-only feature but rather reduce the number of these features in libtock-rs

@jrvanwhy
Copy link
Collaborator

I have no detailled knowledge about the Termination trait but I see two obstacles here:

  • Termination is only available in std as far as I can judge
  • the trait is unstable and I at least I would try to not enable yet another nightly-only feature but rather reduce the number of these features in libtock-rs

I'm referring to this Termination trait:

pub trait Termination {

@torfmaster
Copy link
Collaborator Author

Good point! I added a commit on 103 to implement this and will close this one.

@torfmaster torfmaster closed this Nov 14, 2019
@Woyten Woyten deleted the feature/main_macro branch November 14, 2019 19:20
jrvanwhy added a commit to jrvanwhy/libtock-rs that referenced this pull request Dec 12, 2019
…sync main()` function into a normal `main()` function.

This is based on PR tock#104.
jrvanwhy added a commit to jrvanwhy/libtock-rs that referenced this pull request Dec 12, 2019
…n boards with no LED capsule.

This breaks the existing support for `async` `main()` functions. Instead, an `async_main!()` macro is provided to generate a synchronous `main()` that wraps the provided `async` `main()` function (which, unfortunately, must not be called `main()`).

This solves tock#111 and tock#113.

I would prefer to be more consistent with Tokio and use a procedural macro attribute (as was originally done in tock#104), but I found that has some major drawbacks:
  1. If main() does not parse, the error message does not point to the correct code.
  2. It adds a requirement to update `syn` every time the toolchain is updated.
These drawbacks are elaborated upon in tock#111.
jrvanwhy added a commit to jrvanwhy/libtock-rs that referenced this pull request Dec 12, 2019
…n boards with no LED capsule.

This breaks the existing support for `async` `main()` functions. Instead, an `async_main!()` macro is provided to generate a synchronous `main()` that wraps the provided `async` `main()` function (which, unfortunately, must not be called `main()`).

I would prefer to be more consistent with Tokio and use a procedural macro attribute (as was originally done in tock#104), but I found that has some major drawbacks:
  1. If main() does not parse, the error message does not point to the correct code.
  2. It adds a requirement to update `syn` every time the toolchain is updated.
These drawbacks are elaborated upon in tock#111.

This solves tock#111 and tock#113.
@torfmaster
Copy link
Collaborator Author

I re opened this pull request to have a base for discussion. (#115)

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

Successfully merging this pull request may close these issues.

3 participants