To get the maximum value of an array in Rust, you can use the iter()
method to turn the array into an iterator, then use the max()
method to get the maximum value. Here's an example:
main.rs153 chars6 lines
In this example, arr
is an array of integers. We call the iter()
method on the array to turn it into an iterator, and then call the max()
method on the iterator to get the maximum value. Finally, we use unwrap()
to get the maximum value out of the Option<i32>
type that max()
returns.
This code will output:
main.rs36 chars2 lines
gistlibby LogSnag