Last active
May 18, 2022 15:11
-
-
Save kriogenia/61b66693ed8de7c9a7b2229012422be7 to your computer and use it in GitHub Desktop.
Generify with compiler errors - Starting function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn sum(numbers: &[i32]) -> i32 { | |
let mut total = numbers[0]; | |
for i in numbers.into_iter().skip(1) { | |
total += *i; | |
} | |
total | |
} | |
fn main() { | |
let numbers = vec![23, -4, 3, 10]; | |
let sum = sum(&numbers); | |
assert_eq!(sum, 32); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment