Am I missing something, or are mutable non-reference arguments not supported in Rust?
To give an example, I was playing with Rust and tried to implement Euclid's algorithm generic for all numeric types, and ideally I just wanted to pass arguments by value and have them mutable, but adding keyword mut
to the argument type is rejected by compiler. So I have to declare a mutable copy of the argument as the function prologue. Is this idiomatic/efficent?
use std::ops::Rem;
extern crate num;
use self::num::Zero;
pub fn gcd<T: Copy + Zero + PartialOrd + Rem<Output=T>>(a : T, b : T) -> T
{
let mut aa = a;
let mut bb = b;
while bb > T::zero() {
let t = bb;
bb = aa % bb;
aa = t;
}
aa
}