summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exercises/05_vecs/vecs1.rs14
-rw-r--r--rustlings-macros/info.toml5
-rw-r--r--solutions/05_vecs/vecs1.rs24
3 files changed, 32 insertions, 11 deletions
diff --git a/exercises/05_vecs/vecs1.rs b/exercises/05_vecs/vecs1.rs
index ddcad84..68e1aff 100644
--- a/exercises/05_vecs/vecs1.rs
+++ b/exercises/05_vecs/vecs1.rs
@@ -1,11 +1,9 @@
-// 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!
-
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
- let a = [10, 20, 30, 40]; // a plain array
- let v = // TODO: declare your vector here with the macro for vectors
+ let a = [10, 20, 30, 40]; // Array
+
+ // TODO: Create a vector called `v` which contains the exact same elements as in the array `a`.
+ // Use the vector macro.
+ // let v = ???;
(a, v)
}
@@ -21,6 +19,6 @@ mod tests {
#[test]
fn test_array_and_vec_similarity() {
let (a, v) = array_and_vec();
- assert_eq!(a, v[..]);
+ assert_eq!(a, *v);
}
}
diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml
index cd85dcc..21a27dd 100644
--- a/rustlings-macros/info.toml
+++ b/rustlings-macros/info.toml
@@ -307,8 +307,9 @@ hint = """
In Rust, there are two ways to define a Vector.
1. One way is to use the `Vec::new()` function to create a new vector
and fill it with the `push()` method.
-2. The second way, which is simpler is to use the `vec![]` macro and
- define your elements inside the square brackets.
+2. The second way is to use the `vec![]` macro and define your elements
+ inside the square brackets. This way is simpler when you exactly know
+ the initial values.
Check this chapter: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html
of the Rust book to learn more.
diff --git a/solutions/05_vecs/vecs1.rs b/solutions/05_vecs/vecs1.rs
index 4e18198..55b5676 100644
--- a/solutions/05_vecs/vecs1.rs
+++ b/solutions/05_vecs/vecs1.rs
@@ -1 +1,23 @@
-// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
+fn array_and_vec() -> ([i32; 4], Vec<i32>) {
+ let a = [10, 20, 30, 40]; // Array
+
+ // Used the `vec!` macro.
+ let v = vec![10, 20, 30, 40];
+
+ (a, v)
+}
+
+fn main() {
+ // You can optionally experiment here.
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_array_and_vec_similarity() {
+ let (a, v) = array_and_vec();
+ assert_eq!(a, *v);
+ }
+}