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

Added a different way of vector intialization. #1787

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/std-types/vec.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ fn main() {
// Canonical macro to initialize a vector with elements.
let mut v3 = vec![0, 0, 1, 2, 3, 4];

// specifying the type when initializing a vector.
let mut v4 = Vec::<String>::new();
Copy link
Collaborator

Choose a reason for hiding this comment

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

A more idiomatic way to do this would be

    let mut v4: Vec<String> = Vec::new();

which was covered in the type-inference slide on day 1.

The turbofish operator (::<String>) is introduced in the speaker notes in the impl trait slide in the "Generics" segment and further refined in the sections on FromIterator. I think that's enough coverage for the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A more idiomatic way to do this would be

    let mut v4: Vec<String> = Vec::new();

which was covered in the type-inference slide on day 1.

The turbofish operator (::<String>) is introduced in the speaker notes in the impl trait slide in the "Generics" segment and further refined in the sections on FromIterator. I think that's enough coverage for the moment.

Oh! That's my bad i haven't noticed it. Then lets just close the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you say.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good!


// Retain only the even elements.
v3.retain(|x| x % 2 == 0);
println!("{v3:?}");
Expand Down