Skip to content

feat: allow deriving Deref[Mut] for structs with multiple fields#1

Open
dquirl-R1 wants to merge 1 commit into
frozenlib:masterfrom
dquirl-R1:deref-target
Open

feat: allow deriving Deref[Mut] for structs with multiple fields#1
dquirl-R1 wants to merge 1 commit into
frozenlib:masterfrom
dquirl-R1:deref-target

Conversation

@dquirl-R1

Copy link
Copy Markdown

Allow selecting the target field (and type) for Deref and DerefMut by annotating one of the struct fields with a #[deref] helper attribute.

The implementation checks how many fields are annotated with the attribute so more than one target remains disallowed. This is backwards-compatible with the current "single-field" behaviour as the attribute is not required for single-field structs, which still fall back to their only field automatically.

allow selecting the target field for Deref and DerefMut by annotating it with a `#[deref]` helper attribute like is done for enum variants with `#[default]`

the implementation checks how many fields are annotated with the attribute so more than one target is disallowed and is backwards-compatible with the current "single-field" behaviour as the attribute is not required for single-field structs
@dquirl-R1

Copy link
Copy Markdown
Author

I looked at the other derives to see if any have similar "parameter-less" helper attributes and tried to match the #[default] annotation currently available for deriving Default on enums / selecting a variant, but am happy to change the attribute to something else like #[derive(target)] if you prefer.

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.

1 participant