Passing a mutable reference as an immutable reference

Is it possible to use a mutable reference where an immutable reference is required in Move.

let v: &mut Vector.T<u64>;
...
stack_length = Vector.length<u64>(immutable_reference_of_v_here);

Given that the mutable reference to the vector is required to be live, it is not possible to get an immutable reference to the vector at the same time as the mutable.

I tried using &*copy(v) but then you get an invalid token error.

Is to possible to somehow pass a mutable reference where an immutable reference is required or do you need to move the mutable reference out, get an immutable reference and then get the mutable reference back?

2 Likes

You should be able to use freeze. So

let v: &mut Vector.T<u64>;
...
stack_length = Vector.length<u64>(freeze(copy(v)));
2 Likes