feat(schema): support generic bounds in structs & enums#490
feat(schema): support generic bounds in structs & enums#490nelson137 wants to merge 6 commits intofishfolk:mainfrom
Conversation
b1aa6d0 to
df3e274
Compare
|
Sorry I don't have time to do a proper review, I just want to throw a warning in here because I've messed this up when dealing with generics in the has schema derive: be very careful to make sure that each different instantiation of the generic type's schema returns it's own unique schema. There was a really tricky to debug issue once where generic enums like Sorry that is really hard to say in a way that makes sense. This is the PR that fixed the error I'm talking about: #456 Anyway, warning aside, big thanks for this! |
|
@zicklag thanks for weighing in. I think I ran into that issue once already 😆 My first push had some failing tests and it looked like it was because of the new shared That's the only thing I'm not 100% on, since the rest of the changes are essentially just fixing syntax errors in the derive macro code gen. |
| if let Some(generic_params) = input.generic_params() { | ||
| let mut sync_send_generic_params = generic_params.clone(); | ||
| for (param, _) in sync_send_generic_params.params.iter_mut() { | ||
| let clone_bound = if !no_clone { quote!(+ Clone) } else { quote!() }; |
There was a problem hiding this comment.
lmk if I'm missing anything - but I think we may have dropped the #[schema(no_clone] (i.e. no_clone bool) support here, if this attribute is present, we should not be requiring clone. If reading this right - a no_clone type with generic params will now require clone on its generic types, which previously did not - might not compile with the right instantiation. (we may not have any test coverage or usage that would break in code I'm guessing).
There was a problem hiding this comment.
Really good catch. Fixed, and added a test that will fail to compile if the code gen is broken again.
Changes
HasSchemaderive macrostatic S: OnceLock<parking_lot::RwLock<HashMap<TypeId, &'static Schema>>>for generics intobones_schemaso that user crates don't have to take a dependency onparking_lotGiven the following rust code:
The
HasSchemaderive macro used to generate:With errors:
Now it generates: