Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active November 17, 2024 18:09
Show Gist options
  • Save dacr/bcae29a5943eb058ebd6e7ba24762252 to your computer and use it in GitHub Desktop.
Save dacr/bcae29a5943eb058ebd6e7ba24762252 to your computer and use it in GitHub Desktop.
hello rust collections / published by https://github.com/dacr/code-examples-manager #cf68580c-da79-41e2-aee1-5c3be26848a3/77b382ed856093a107837a57e7344bbaf0d27c6f
#!/usr/bin/env rust-script
// summary : hello rust collections
// keywords : rust, collections, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : cf68580c-da79-41e2-aee1-5c3be26848a3
// created-on : 2024-10-14T22:27:38+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : ./$file
fn col1() {
let v = vec![1, 2, 3, 4, 5, 6];
for point in &v {
println!("Point is {}", point);
}
let sum = &v.into_iter().reduce(|a, b| a + b);
// ⚠️ v has been consumed ! AND is no longer accessible
println!("Sum is {:?}", sum.ok_or(0));
}
fn main() {
col1();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment