You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I needed support for specializing some method implementations in the generated traits for each case, while having a single implementation for the rest of the trait. What I came up with is a #[when] attribute that can be used on methods within a #[trait_gen] trait, for example
#[trait_gen(DB -> sqlx::sqlite::Sqlite, sqlx::mysql::MySql, sqlx::postgres::Postgres)]#[async_trait]implRepofor sqlx::Pool<DB>{// ...#[when(sqlx::sqlite::Sqlite -> update)]asyncfnupdate_sqlite(&self,id:u64,param:String) -> Result<(),String>{// SQLite specific implementationtodo!()}#[when(sqlx::mysql::MySql -> update)]asyncfnupdate_mysql(&self,id:u64,param:String) -> Result<(),String>{// MySQL specific implementationtodo!()}// ...
Glad it was useful! It started as a proof-of-concept when I fancied writing an RFC for something similar in the language, but I don't think many would find it interesting.
That's a nice feature you added. Yes, I think I'd like to merge that, at some point.
I also need to upgrade the code to support syn version 2.0 (and other dependencies), or it won't be able to parse the new Rust syntax elements. I won't do that in the next coming weeks because I'm full-time on another project. So it's as you wish, but by default, I'll grab the modification from your fork when the time comes, before tackling the 2.0 upgrade. That way, if you still want to modify your code, you won't have to bother with this repository.
I quickly went over the modifications. I'll definitely merge it on my own (and give all the due credits) because I see there's a lot of reformatting that'll make the merge a little tricky and dependencies for the tests that I won't integrate in order to keep the crate as independent as possible (tokio).
Thank you for the nice crate!
I needed support for specializing some method implementations in the generated traits for each case, while having a single implementation for the rest of the trait. What I came up with is a
#[when]
attribute that can be used on methods within a#[trait_gen]
trait, for exampleAs I needed this quickly, I published it as a fork: https://github.com/vigoo/conditional_trait_gen
But if you are interested, I'm happy to open a PR with it upstream.
The text was updated successfully, but these errors were encountered: