Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:24
Show Gist options
  • Select an option

  • Save dacr/bcae29a5943eb058ebd6e7ba24762252 to your computer and use it in GitHub Desktop.

Select an option

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/47dd2e53e2a1f08f6c480fec15486f84db2fdbf4
#!/usr/bin/env rust-script
// summary : hello rust collections
// keywords : rust, collections, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// 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