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

Replace the crate async_trait with rust native support #1972

Closed
2 tasks done
AmmarAbouZor opened this issue Jan 4, 2024 · 8 comments
Closed
2 tasks done

Replace the crate async_trait with rust native support #1972

AmmarAbouZor opened this issue Jan 4, 2024 · 8 comments
Assignees
Labels
idea native implemented in the rust part (natively) rust Pull requests that update Rust code

Comments

@AmmarAbouZor
Copy link
Member

Prerequisites

affected version: Master

make sure to check this before filing an issue:

  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Describe what you would like to have

Native support for async traits has been added to rust form Version 1.75, which should be able to replace using the crate async_trait in the most cases, especially with a stand-alone application where no other apps have dependencies on the codes like with libraries to consider.

I want to try to replace the crate async_trait with the native rust solution, but at first I want to make sure that there are no problems to enforce the developers to use rust Version 1.75+.
Besides that we need to adjust the GitHub Pipelines to make sure that the latest rust version is installed

@github-actions github-actions bot added the new newly created issue label Jan 4, 2024
@DmitryAstafyev
Copy link
Collaborator

make sense

@AmmarAbouZor
Copy link
Member Author

@DmitryAstafyev Should I try to implement this in the CLI tool at first, or it's better to wait to make sure that there is no problem with forcing the minimum rust Version to be 1.75?

@DmitryAstafyev
Copy link
Collaborator

@AmmarAbouZor hello.
I think CLI stuff and this issue don't depend on each other. For CLI we already have PR. As for this issue, it can go as a separate PR and you are welcome to create it from your fork as well.

@AmmarAbouZor
Copy link
Member Author

@DmitryAstafyev I thought it would some restriction because some developers in the team can't install rust Version 1.75, then they can't build either the app or the CLI-tool.
I'll provide a PR to CLI-tool at first to check if we can apply it since the native support has its restrictions with concurrency too.

@AmmarAbouZor
Copy link
Member Author

So I've tried to apply the native async-trait on the CLI-tool and got some weird build error about cycles inside the traits, then I've tried to build it using rust nightly to get error messages which make sense:

    --> src/target.rs:48:30
    |
48  |     pub fn get(&self) -> Box<dyn Manager + Sync + Send> {
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^ `Manager` cannot be made into an object
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
   --> src/modules/mod.rs:78:14
    |
61  | pub trait Manager {
    |           ------- this trait cannot be made into an object...
...
78  |     async fn reset(&self) -> Result<SpawnResult, Error> {
    |              ^^^^^ ...because method `reset` is `async`

After reading the announcement of async traits in rust blog I've found out that dynamic dispatch still not supported with native rust. link.

I think we can postpone this until there is a proper support for native async-traits in rust.

@DmitryAstafyev Should we leave this issue open as reminder to check the progress of this issue with rust or we can just close it and open another once the native support is there?

@sudeeptarlekar sudeeptarlekar self-assigned this Feb 14, 2024
@AmmarAbouZor
Copy link
Member Author

To Info: I could replace the async trait in the indexer project with the native async rust but we decided to postpone it for a little to make sure all build systems support rust version 1.75

sudeeptarlekar added a commit to sudeeptarlekar/chipmunk that referenced this issue Feb 19, 2024
From Rust1.75 onwards async support was added so we do not need
async-trait crate anymore. Removed this crate in this PR and
used native async support.

Resolves: esrlabs#1972
@DmitryAstafyev
Copy link
Collaborator

DmitryAstafyev commented Feb 19, 2024

@AmmarAbouZor sorry, I've missed your comment. Let's focus on CLI... this issue "linked" to @sudeeptarlekar. It's in the draft/research state and doesn't have hi-priority for now.

@marcmo marcmo added idea native implemented in the rust part (natively) rust Pull requests that update Rust code and removed new newly created issue labels Apr 11, 2024
@DmitryAstafyev
Copy link
Collaborator

Looks like doesn't make sense in the scope of current generation of chipmunk. I would close it. But with next generation of chipmunk we can think about design with native async trait support. Or, it can be good solution too, just return from methods boxed features, instead having async fn()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea native implemented in the rust part (natively) rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants