specta-rs / tauri-specta

Completely typesafe Tauri commands
MIT License
396 stars 41 forks source link

Allow `::` in `collate_types!` macro #1

Closed probablykasper closed 1 year ago

probablykasper commented 2 years ago

The collate_types! macro doesn't let you reference commands from other modules: image

Tauri's generate_handler! macro does, so hopefully it's possible to make it work: https://github.com/tauri-apps/tauri/blob/b6027b2dd298caccd879b8abf93532ea39354077/core/tauri-macros/src/lib.rs#L49-L51

Brendonovich commented 1 year ago

Turns out macro_rules isn't powerful enough to handle what collate_types needs to do, so we'll have to take some inspiration from Tauri and do a similar proc macro.

oscartbeaumont commented 1 year ago

I have started work on this. Will try and finish over the weekend.

Brendonovich commented 1 year ago

Should be fixed in 9107481a475ca832fdb895e4f8c091b907b7dc36, requires using the tauri-specta-changes branch of specta.

probablykasper commented 1 year ago

Unfortunately doesn't seem to work for me, unless I'm doing something wrong:

export_to_ts(collate_types![data::get_settings], "../bindings.ts").unwrap();
failed to resolve: could not find `__specta__fn__get_settings` in `data`
could not find `__specta__fn__get_settings` in `data`
Brendonovich commented 1 year ago

Hmm, will have to pay more attention to what the tauri's generate_handler! does

Brendonovich commented 1 year ago

Pretty much copied Tauri's macro code, should work on 44d5342ee7c98cc466e271a5bc548c8989d9be7f