rustlings/exercises/05_vecs/vecs1.rs

25 lines
477 B
Rust
Raw Normal View History

2020-10-26 06:54:32 +00:00
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
2024-06-20 00:00:06 +01:00
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 = ???;
2020-10-26 06:54:32 +00:00
(a, v)
}
fn main() {
// You can optionally experiment here.
}
2020-10-26 06:54:32 +00:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_array_and_vec_similarity() {
let (a, v) = array_and_vec();
2024-06-20 00:00:06 +01:00
assert_eq!(a, *v);
2020-10-26 06:54:32 +00:00
}
}