Last active
June 21, 2020 09:01
-
-
Save timClicks/809fa86c5ae1aa26ec9bb42a4a4df401 to your computer and use it in GitHub Desktop.
How to .zip() through items in two arrays in Rust
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
fn main() { | |
let x_coordinates: [f32; 4] = [0., 1., 2., 3.]; | |
let y_coordinates: [f32; 4] = [0., 1., 4., 9.]; | |
for (x, y) in x_coordinates.iter().zip(y_coordinates.iter()) { | |
// Comparisons require that you dereference the values. | |
// iter() for arrays returns a reference to each element. | |
if *x <= 0.0 || *y <= 1.0 { | |
continue; | |
} | |
// Most of the time though, Rust's auto-dereferencing rules | |
// help us out to remove some of the noise. | |
println!("x = {}; ln(y) = {}", x, y.ln()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment