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 VariantData#fields_mut #26

Closed
wants to merge 1 commit into from
Closed

Add VariantData#fields_mut #26

wants to merge 1 commit into from

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Oct 3, 2016

This adds the mutable equivalent to VariantData#fields, and can make
code which needs to mutate those fields a bit less verbose.

This adds the mutable equivalent to `VariantData#fields`, and can make
code which needs to mutate those fields a bit less verbose.
match *self {
VariantData::Struct(ref mut fields) |
VariantData::Tuple(ref mut fields) => fields,
VariantData::Unit => &mut [],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was shocked that this worked. I get that it's completely valid from a memory safety point of view since there's no operation that could actually mutate an empty slice, but I didn't think the compiler would special case empty slices vs non-empty here.

@dtolnay
Copy link
Owner

dtolnay commented Oct 3, 2016

There are some breaking changes sitting in master so I cherry-picked this across to the 0.8 branch as 15085c4 and released it in 0.8.6. Thanks!

@dtolnay dtolnay closed this Oct 3, 2016
@dtolnay dtolnay deleted the sg-fields-mut branch October 3, 2016 16:22
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