From 4dfc11d74ab02ac5765ae5d08fb750c91f4744b4 Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Fri, 2 Oct 2026 21:53:51 -0500 Subject: rustlings: move to rust/ --- rustlings/solutions/05_vecs/vecs1.rs | 23 --------------- rustlings/solutions/05_vecs/vecs2.rs | 55 ------------------------------------ 2 files changed, 78 deletions(-) delete mode 100644 rustlings/solutions/05_vecs/vecs1.rs delete mode 100644 rustlings/solutions/05_vecs/vecs2.rs (limited to 'rustlings/solutions/05_vecs') diff --git a/rustlings/solutions/05_vecs/vecs1.rs b/rustlings/solutions/05_vecs/vecs1.rs deleted file mode 100644 index 55b5676..0000000 --- a/rustlings/solutions/05_vecs/vecs1.rs +++ /dev/null @@ -1,23 +0,0 @@ -fn array_and_vec() -> ([i32; 4], Vec) { - 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); - } -} diff --git a/rustlings/solutions/05_vecs/vecs2.rs b/rustlings/solutions/05_vecs/vecs2.rs deleted file mode 100644 index 87f7625..0000000 --- a/rustlings/solutions/05_vecs/vecs2.rs +++ /dev/null @@ -1,55 +0,0 @@ -fn vec_loop(input: &[i32]) -> Vec { - let mut output = Vec::new(); - - for element in input { - output.push(2 * element); - } - - output -} - -fn vec_map_example(input: &[i32]) -> Vec { - // An example of collecting a vector after mapping. - // We map each element of the `input` slice to its value plus 1. - // If the input is `[1, 2, 3]`, the output is `[2, 3, 4]`. - input.iter().map(|element| element + 1).collect() -} - -fn vec_map(input: &[i32]) -> Vec { - // We will dive deeper into iterators, but for now, this is all what you - // had to do! - // Advanced note: This method is more efficient because it automatically - // preallocates enough capacity. This can be done manually in `vec_loop` - // using `Vec::with_capacity(input.len())` instead of `Vec::new()`. - input.iter().map(|element| 2 * element).collect() -} - -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_vec_loop() { - let input = [2, 4, 6, 8, 10]; - let ans = vec_loop(&input); - assert_eq!(ans, [4, 8, 12, 16, 20]); - } - - #[test] - fn test_vec_map_example() { - let input = [1, 2, 3]; - let ans = vec_map_example(&input); - assert_eq!(ans, [2, 3, 4]); - } - - #[test] - fn test_vec_map() { - let input = [2, 4, 6, 8, 10]; - let ans = vec_map(&input); - assert_eq!(ans, [4, 8, 12, 16, 20]); - } -} -- cgit v1.2.3