Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support adding additional annotations to the Path structs #24

Closed
amircodota opened this issue Feb 25, 2024 · 5 comments · Fixed by #29
Closed

support adding additional annotations to the Path structs #24

amircodota opened this issue Feb 25, 2024 · 5 comments · Fixed by #29

Comments

@amircodota
Copy link

We currently have #{patch_derive] which allows adding derive macros to the generated patch structs.

It would be nice to add additional attributes (not sure I'm using the right term here :-)).

For example, it would be nice to add the serde_with crate annotations to both generated Patch structs or the struct fields.

@yanganto
Copy link
Owner

yanganto commented Feb 26, 2024

Could you give a short code snippets you want to use here? That will be easier to help you.

@amircodota
Copy link
Author

#[derive(Patch, Debug)]
#[patch_derive(Serialize, Deserialize, Default)]
struct Data {
    value: String,
    num: usize,
}

This will generate

#[derive(Serialize, Deserialize, Default)]
struct PatchData {
  value: Option<String>,
  num: Option<usize>,
}

But I would like to have some way to specify that it should be generated with additional macro attributes

#[derive(Serialize, Deserialize, Default)]
#[skip_serializing_none]
struct PatchData {
  value: Option<String>,
  num: Option<usize>,
}

where the skip_serializing_none macro comes from the serde_with crate.

Maybe have a #[patch_attribute] that's similar to #[patch_derive]

use serde_with::skip_serializing_none;

#[derive(Patch, Debug)]
#[patch_derive(Serialize, Deserialize, Default)]
#[patch_attribute(skip_serializing_none)]
struct Data {
    value: String,
    num: usize,
}

Ideally I could apply this macro to both the struct and its fields

@yanganto
Copy link
Owner

Hi @amircodota,

Thanks for the code snippets, I tried, but there seems to be some restriction.
I am not sure it is possible to do it.
It is sorry I can not provide this quickly, please kindly understand.

@amircodota
Copy link
Author

np 👍

Thanks for trying

@taorepoara
Copy link
Contributor

I think that a good solution to add behaviors with global patch attribute that can be parsed to a struct, just like it's done in serde. This could ease the implementation of new features and the add of new attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants