Skip to content

Instantly share code, notes, and snippets.

@kriogenia
Last active May 18, 2022 15:11
Show Gist options
  • Save kriogenia/61b66693ed8de7c9a7b2229012422be7 to your computer and use it in GitHub Desktop.
Save kriogenia/61b66693ed8de7c9a7b2229012422be7 to your computer and use it in GitHub Desktop.
Generify with compiler errors - Starting function
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