Open ia0 opened 6 months ago
I am very open to getting this fixed, but my proc-macro skills are fairly limited. If you can find a way to do it, I'm all ears.
The logic to infer perfect bounds is quite complex, but serde also provides a way to overwrite the bounds using #[serde(bound = "...")]
. This is more general (it always works) but needs the user to write the bounds themselves. In my case this is simple because there are no bounds, i.e. I just need #[postcard(bound = "")]
(similar to the added test in #154). Because this is simpler to implement and more general, I went this way. User convenience could be added later by guessing the perfect bounds like in serde
if there is demand.
This is a known issue in Rust that
derive(Clone)
,derive(PartialEq)
, etc., don't infer the proper bounds. They will require each type parameter to implement the trait instead of looking at what is actually needed by the type definition (called perfect derive).For some reason,
serde
derive macros do perfect derive. It would be nice ifSchema
derive macro would also do so. Here is a small reproduction example:Running
cargo test
gives the following error:In particular, it thinks that
Id
must implementSchema
, while onlyId::Type<Foo<'a>>
(i.e.Foo<'a>
) needs to.When looking at the
cargo expand
output, we can see the difference betweenserde::Serialize
andpostcard::Schema
:This issue is blocking #143.