diff --git a/exercises/collections/README.md b/exercises/collections/README.md index b6d62acb..30471cf9 100644 --- a/exercises/collections/README.md +++ b/exercises/collections/README.md @@ -1,23 +1,11 @@ -# Collections +# Hashmaps +A *hash map* allows you to associate a value with a particular key. +You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map), +[*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages. -Rust’s standard library includes a number of very useful data -structures called collections. Most other data types represent one -specific value, but collections can contain multiple values. Unlike -the built-in array and tuple types, the data these collections point -to is stored on the heap, which means the amount of data does not need -to be known at compile time and can grow or shrink as the program -runs. - -This exercise will get you familiar with two fundamental data -structures that are used very often in Rust programs: - -* A *vector* allows you to store a variable number of values next to - each other. -* A *hash map* allows you to associate a value with a particular key. - You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map), - [*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages. +This is the other data structure that we've been talking about before, when +talking about Vecs. ## Further information -- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) - [Storing Keys with Associated Values in Hash Maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) diff --git a/exercises/vecs/README.md b/exercises/vecs/README.md new file mode 100644 index 00000000..ebe90bf3 --- /dev/null +++ b/exercises/vecs/README.md @@ -0,0 +1,15 @@ +# Vectors + +Vectors are one of the most-used Rust data structures. In other programming +languages, they'd simply be called Arrays, but since Rust operates on a +bit of a lower level, an array in Rust is stored on the stack (meaning it +can't grow or shrink, and the size needs to be known at compile time), +and a Vector is stored in the heap (where these restrictions do not apply). + +Vectors are a bit of a later chapter in the book, but we think that they're +useful enough to talk about them a bit earlier. We shall be talking about +the other useful data structure, hash maps, later. + +## Further information + +- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) diff --git a/exercises/collections/vec1.rs b/exercises/vecs/vecs1.rs similarity index 84% rename from exercises/collections/vec1.rs rename to exercises/vecs/vecs1.rs index c26f5691..4e8c4cbb 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/vecs/vecs1.rs @@ -1,8 +1,8 @@ -// vec1.rs +// vecs1.rs // Your task is to create a `Vec` which holds the exact same elements // as in the array `a`. // Make me compile and pass the test! -// Execute `rustlings hint vec1` or use the `hint` watch subcommand for a hint. +// Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/collections/vec2.rs b/exercises/vecs/vecs2.rs similarity index 92% rename from exercises/collections/vec2.rs rename to exercises/vecs/vecs2.rs index db37d1d6..5bea09a2 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/vecs/vecs2.rs @@ -1,10 +1,10 @@ -// vec2.rs +// vecs2.rs // A Vec of even numbers is given. Your task is to complete the loop // so that each number in the Vec is multiplied by 2. // // Make me pass the test! // -// Execute `rustlings hint vec2` or use the `hint` watch subcommand for a hint. +// Execute `rustlings hint vecs2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index af4861c2..1e941e13 100644 --- a/info.toml +++ b/info.toml @@ -242,8 +242,8 @@ Now you have another tool in your toolbox!""" # VECS [[exercises]] -name = "vec1" -path = "exercises/collections/vec1.rs" +name = "vecs1" +path = "exercises/vecs/vecs1.rs" mode = "test" hint = """ In Rust, there are two ways to define a Vector. @@ -256,8 +256,8 @@ of the Rust book to learn more. """ [[exercises]] -name = "vec2" -path = "exercises/collections/vec2.rs" +name = "vecs2" +path = "exercises/vecs/vecs2.rs" mode = "test" hint = """ Hint 1: `i` is each element from the Vec as they are being iterated. Can you try