I can't understand why Rust complains ("can't borrow as immutable because also borrowed as mutable") in this code (even considering that .len() is a "constant/harmless" function):
fn main() {
let mut xs1: [i32; 5] = [ 10, 20, 30, 40, 50];
let (slice1, slice2) = xs1.split_at_mut( (xs1.len()/2) ); // <----- ERROR
println!( "{:?}", slice1 );
println!( "{:?}", slice2 );
} // ()
While the split version is fine:
let aux = xs1.len()/2;
let (slice1, slice2) = xs1.split_at_mut( aux );
What's the rationale here?
Maybe I'm wrong but I always regarded both expressions as "mathematically equivalent" so to say. Not only len() should be a const method but also the input param for split_at_mut() should be const (in C++ parlance).
Still holding this question eight years later?