Files
compiler-explorer/examples/rust/Max_array.rs
Tony Yang 2501734007 Fix Rust Max_array examples (#1960)
* Fix Max_array.rs iter_mut is not necessary

The previous example failed to compile as `y` was not borrowed as a mutable reference but used to produce a mutable iterator. Changing from `iter_mut()` to `iter()` resolved this issue.

* Fix Max_array_(Optimized).rs

The previous example failed to compile as `y` was not borrowed as a mutable reference but used to produce a mutable iterator. Changing from `iter_mut()` to `iter()` resolved this issue.
2020-05-11 01:03:13 +02:00

6 lines
158 B
Rust

pub fn max_array(x: &mut [f64; 65536], y: &[f64; 65536]) {
for (x, y) in x.iter_mut().zip(y.iter()) {
*x = if *y > *x { *y } else { *x };
}
}