1. 4
    Rustlings variables3: Using the mut keyword to declare a mutable variable
    46s

Rustlings variables3: Using the mut keyword to declare a mutable variable

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

README for this exercise

Chris Biscardi: [0:00] For variables3, we have our main function again with an x that equals three, a println macro that prints the number, a reassignment of x to five, and another println macro that prints the number again.

[0:11] Here in our error, we can see that we cannot assign twice to an immutable value. The error points to x and says the first assignment to x help make this binding mutable, mut x. Then, follows up with the error that we saw above cannot assign twice to immutable value.

[0:26] We're doing an assignment here and an assignment here. Because Rust is immutable by default, we can't assign twice to a single value because that would mutate the value. As seen in the error message, we can use the mut keyword to set the x variable to immutable value. This lets us assign to x a second time.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today