Last active
November 17, 2024 18:09
-
-
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
This file contains hidden or 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
#!/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