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

Add field attributes (aliases, ignore, rename) for derive FormatArgs #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

smith61
Copy link
Contributor

@smith61 smith61 commented Jun 1, 2017

Implements support for field attributes when using #derive(FormatArgs) on a struct. Adding these attributes allows for hiding of internal fields, or providing backwards compatible names for given fields.

aliases - Comma separated list of alternative names for the provided field.
ignore - If set, field is hidden from format strings.
rename - Overrides the default name for a given field.

This pull request also refactored most of the generation code. While the generated code mostly matches, regular structs now also support indices similar to tuple structs and tuple structs can have named fields using the added attributes. This was done to unify the code and make it agnostic of struct type.

@smith61
Copy link
Contributor Author

smith61 commented Jun 1, 2017

Ideas for possible future attributes:

  • Virtual fields of a struct
  • Rename all to auto rename all non-ignored fields (Similar to serde's rename_all attribute)
  • Override getter for a field
  • Override get_child/as_usize for a field

@SpaceManiac
Copy link
Owner

Thanks for the PR! These features look really useful, and mirror serde's quite nicely. Due to the size of the changes and the complex code, it might take me some time to review.

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 this pull request may close these issues.

2 participants