Skip to content

The book chapter on struct would benefit from clarifying that the type of struct fields can be mut #30254

Closed
@hsivonen

Description

@hsivonen

As a newbie, I made the mistake that can be witnessed with the field slice in this question about other stuff.

The way this happened is that I vaguely remembered that you can't use mut when specifying the fields of struct and to make sure, I looked up the struct chapter in the book. Sure enough, it said "Mutability is a property of the binding, not of the structure itself."

Now, as a newbie, I thought this forbade mut in field definitions altogether even though it only forbids mut to the left of the colon and you can still have &mut as the type to the right of the colon.

It would be nice if this was briefly clarified for the benefit of newbies looking stuff up piecemeal and not properly thinking about stuff in the context of what has previously been said in an earlier chapter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions