1. 42
    Rustlings move_semantics4: Initializing a vector with the vec! macro
    57s

Rustlings move_semantics4: Initializing a vector with the vec! macro

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] Move_semantics4 set up in a very similar way to the last three move_semantics exercises. The difference is that fill_vec() doesn't take anything as an argument.

[0:09] On line 23, the Rust compiler tells us that it expected value and found macro 'vec'. That's because to initialize a new vector, we can use the vec! Macro.

[0:17] Note that there are a number of values we can use here where we're going to use an empty vector to start. Also, note that the Rust compiler expected us to do something after the vec! Macro.

[0:26] Finally, we're still passing in vec0 on line 12 to the fill_vec() function. Fill_vec() doesn't take any arguments, so we will remove zero. Note that Vec: :new can no longer infer of the type that the values inside of the vector in half, but this is fine because we aren't actually using vec0 anymore.

[0:44] We'll just delete that entire line. Now our code compiles. We have a mutable vector that we fill via a separate function that takes no arguments and returns us a new vector created with the vec! Macro that we can then push(88) into later.

egghead
egghead
~ 35 minutes 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