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

endpoints! and topics! macros don't accept generic type parameters #56

Open
jamesmunns opened this issue Nov 4, 2024 · 1 comment
Open
Labels
bug Something isn't working open to sponsorship This issue is something James wants, and would be willing to prioritize as sponsored/contract work

Comments

@jamesmunns
Copy link
Owner

In v0.10, I made it so that endpoints and topics could accept types with lifetimes, e.g.:

topics! {
    list = TOPICS_IN_LIST;
    direction = postcard_rpc::TopicDirection::ToServer;
    | TopicTy       | MessageTy             | Path      | Cfg                           |
    | ----------    | ---------             | ----      | ---                           |
    | ZetaTopic1    | ZMsg                  | "zeta1"   |                               |
    | BorrowTopic   | Message<'a>           | "msg1"    | cfg(feature = "alpha")        |
    | BorrowTopic   | DoubleMessage<'a, 'b> | "msg1"    | cfg(not(feature = "alpha"))   |
}

However I wasn't able to figure out how to accept lifetimes AND/OR types, which means that generic types require an alias. This doesn't work (because we try and interpret the stuff between <> as lifetimes):

topics! {
    list = TOPICS_IN_LIST;
    direction = postcard_rpc::TopicDirection::ToServer;
    | TopicTy       | MessageTy             | Path      |
    | ----------    | ---------             | ----      |
    | ZetaTopic1    | Result<u16, u32>      | "zeta1"   |
}

But this does:

pub type ZetaAlias = Result<u16, u32>;
topics! {
    list = TOPICS_IN_LIST;
    direction = postcard_rpc::TopicDirection::ToServer;
    | TopicTy       | MessageTy             | Path      |
    | ----------    | ---------             | ----      |
    | ZetaTopic1    | ZetaAlias             | "zeta1"   |
}

This is not good UX, and should be fixed. I am open to improvements of the macro syntax to re-allow this, it will likely require some kind of fancier tt-muncher or something to separately collect the types and generics.

@jamesmunns jamesmunns added the bug Something isn't working label Nov 4, 2024
@jamesmunns
Copy link
Owner Author

jamesmunns commented Nov 4, 2024

Note that this also applies to some other types, like arrays ([u8; 16]) or tuples ((u32, u8, i32)), which will also require an alias.

@jamesmunns jamesmunns added the open to sponsorship This issue is something James wants, and would be willing to prioritize as sponsored/contract work label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working open to sponsorship This issue is something James wants, and would be willing to prioritize as sponsored/contract work
Projects
None yet
Development

No branches or pull requests

1 participant