Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements #72
The idea is similar to serde's skip. The getter/setter is not implemented for fields that are marked
#[getset(skip)]
. So for:only
fn copyable(&self) -> usize
getter is generated. This feature makes sense for larger structs, where using struct-level attribute is convenient for brevity, but the user still wants to ignore a subset of fields. It is possible to achieve this behavior in the current version by annotating each field with a correspondinggetset
attribute and not annotating the fields for which the getter/setter should not be generated.This PR lacks thorough testing and documentation, I wanted to be sure this is a way to go before writing the tests and docs.
Open questions I can think of:
getset
attribute. For the example above, it means that if I use#[getset(get_copy, skip)]
, it silently swallows the "get_copy" part and skips the field, but if I use#[getset(skip, get_copy)]
, the last identifier (i.e., "get_copy") is taken and the getter is generated (resulting into a compilation error for moving a non-copyable value). This is inconsistent and confusing for the user. I think it should be forbidden to use any other identifier ifskip
is present, but there is also point 2.Getters
andSetters
and the user wants to omit the setter part on a field. Shouldgetset
support this too by a more granular syntax (e.g.,getset(skip(get))
orget(skip)
orgetset(skip_get)
) or is it out of scope? (Thegetset(skip_get)
syntax is inspired by serde'sskip_serializing
.)