ModProg / derive-where

Attribute proc-macro to simplify deriving standard and other traits with custom generic type bounds.
Apache License 2.0
59 stars 3 forks source link

`derive_where` for serde #100

Open DCNick3 opened 1 month ago

DCNick3 commented 1 month ago

Would it be possible to support serde derive macros (Serialize & Deserialize) in derive-where?

Currently, if you put fields from associated types, you have to manually put #[serde(bounds(serialize = "XXX: Serialize", deserialize = "XXX: Deserialize<'de>"))], which can amount to a lot of boilerplate, and might not even be possible to generate in declarative macros (at least I didn't find any way to).

To not reimplement the whole serde in this crate, you can just emit the corresponding #[serde(bounds)] and hand off the rest to the upstream derive macro

daxpedda commented 1 month ago

To not reimplement the whole serde in this crate, you can just emit the corresponding #[serde(bounds)] and hand off the rest to the upstream derive macro

We talked about this a long time ago and our main reason not to do this was that reimplementing Serde would be an ungodly amount and error-prone work. But just emitting the corresponding attributes might be reasonable.

I would have to take a deeper look, but in favor.

ModProg commented 1 month ago

It doesn't sound too bad to do, and you are probably right that it wouldn't be possible to emit serde's syntax with declarative macros, because string concatenation only works in certain positions (like the built-in doc attribute).

DCNick3 commented 2 weeks ago

I tried implementing this as part of derive-where, but a big chunk of the code is coupled tightly to generating actual impl blocks, not emitting attributes. I am not familiar with the codebase, so I was not able to come up with a localized API change that would work here