ayrat555 / frankenstein

Telegram bot API client for Rust
Do What The F*ck You Want To Public License
268 stars 28 forks source link

refactor!: simplify traits with macros #210

Closed EdJoPaTo closed 1 month ago

EdJoPaTo commented 1 month ago

Utilise macros to do the repetitive stuff.

This automatically adds doc comments with a link to the Telegram API of the given method.

BREAKING CHANGE: request_without_body method is gone. This was meant to be used internally and probably not used elsewhere.

BREAKING CHANGE: AsyncTelegramApi requires Sync. This was likely the case already via #[async_trait] but wasn't explicitly specified.

EdJoPaTo commented 1 month ago

Due to the breaking changes… it might be easier as separate PR to see what exactly what changed and what is the diff of the break. The macro usage changes a lot and has a hard to read diff. Due to the multiple commits it’s also easy to split up…

Edit: done with #211 and #212

EdJoPaTo commented 1 month ago

I kind of assume that the async trait might be fishy now as there are warnings that weren't there with async_trait. I kind of assume that the trait doesn't work on the macro created functions and that this change silently uses Rust 1.75 to function now. See https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html

Not sure how to deal with that. I think it's easy to ignore as people will not implement them manually. It's for the methods provided by frankenstein, not the methods to be implemented when implementing the trait yourself. So it's likely not a big deal at all. We should probably test this extra carefully.

EdJoPaTo commented 1 month ago

I think this can be an accepted risk. This only affects provided methods of the trait, nothing someone will implement manually. The methods to be implemented stay the same. I tested it with an async bot of mine and it runs fine.

In case this ends up ugly we can still revert, but I don't think there is much risk.