-
Notifications
You must be signed in to change notification settings - Fork 4
feat!: Implement support for generic params #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
Conversation
…write of the macro expansion.
…. WIP: Make macros work with traits.
… TODO: check parsing of trait-inner type-generic attributes on functions
…O: check parsing of trait-inner type-generic attributes on functions
|
Hello, @scouten. Ready for review |
|
Should be marked as "Closes #16" |
Needs to be new major, because async_signature now requires to explicitly specify or not specify the return type
|
I need to add support for |
|
Or rather, attributes on |
…utes on `async_signature`
|
Battle-testing the implementation on |
|
@DanikVitek this looks very interesting. I'll want to make sure the CI runs pass before merging and also for you to add the Let me know how I can help. |
scouten
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great and welcome proposal! I look forward to the final draft as discussed in my initial comments.
…ersions, storing only respective kind of functions, and llow to specify custom trait bounds on async version
|
I might also add the |
I need to add new features behind feature flags? |
… to remove confusion with the `async_trait` macro
We haven't encountered that situation yet, but I wouldn't completely rule it out. Possible the return type could be something that implements a different type in sync vs async worlds. We do have that situation routinely for function parameters. |
scouten-adobe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really impressive change and looks very well thought out.
This takes me beyond my knowledge level for Rust's proc-macros. If we merge this, would you be willing to join me as a co-maintainer of this crate?
| async-std = { version = "1.0", features = ["attributes"] } | ||
| trybuild = { version = "1.0", features = ["diff"] } | ||
| async-trait = "0.1" | ||
| trybuild = { version = "<=1.0.90", features = ["diff"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the issue with newer versions of trybuild?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it required a higher MSRV. I wanted to lower the MSRV to 1.67
Sure, I'd be happy to |
|
@DanikVitek I've sent you an invite to collaborator status. Looks like there are a few Clippy and rustfmt details to sort out before we merge this, but once the tests run, feel free to proceed. |
|
i'll post 2 suggestions which appear reasonable to me, though they might not be reasonable at all and totally fine to be ignored:
#[async_generic(
async_signature =
fn <'a, W: AsyncWrite>(&'a self, writer: &'a mut W) -> impl Future<Output = Result<()>> + Send + 'a
)]
...
#[async_generic(
async_signature =
async fn <'a, W: AsyncWrite>(&'a self, writer: &'a mut W) -> Result<()>
)]
@if_sync_async_expr [
_sync {
/// ....
} _async {
/// ...
}
]or smth else of that kind, so that it's clearly visible that it's special proc-macro magic and not regular rust syntax. |
@dj8yfo @scouten regarding this, I've came up with 5 "modes" alongside the
I'm not sure how else to better indicate this niche behavior, but open for suggestions |
|
@DanikVitek well, then maybe just split it into |
|
Also |
@dj8yfo Also, the next question is how to assign attributes on the signatures? Like this: #[async_generic(
async_signature =
/// docs
#[cfg(feature = "async")]
async fn <'a, W: AsyncWrite>(&'a self, writer: &'a mut W) -> Result<()>
)]or the same way it was before: #[async_generic(
/// docs
#[cfg(feature = "async")]
async_signature =
async fn <'a, W: AsyncWrite>(&'a self, writer: &'a mut W) -> Result<()>
)]? |
|
And the function signature is tied to its mode, so |
this can be enforced by a diagnostic, and the user may experiment with wrong combinations and learn about it from diagnostic |
this looks better, but maybe you could consider splitting this into #[async_generic(
async_variant_attributes = (
#[doc = "....."]
#[cfg(feature = "async")]
),
async_signature =
async fn <'a, W: AsyncWrite>(&'a self, writer: &'a mut W) -> Result<()>
)]This way it could be also mentioned on the |
|
My sincere apologies for letting this linger for a long time. I have some split loyalties here – I'd like to take this change, but I also realize that I need to keep this simple enough that I can rely on and maintain this crate for use by my team (see https://crates.io/c2pa). For that reason, I've decided not to merge this PR. I'd like to invite you to take the work done in this PR into a new more advanced generic crate. Please use any existing code from |
Also:
Closes #16.