What is the difference between fn(inout v: T) and fn(ref v: T) ?
Both work the same if the Origin is inferred for
ref
? What are the differences?3 Replies
fn foo(ref v: T)
is generic over mutability. You can use __origin_of(v).is_mutable
to check that.So, when I use inout, the variable should be mutable. Otherwise, I'll get compiler error I guess. But ref can use both mutable and immutable. Is my statement correct?
Yes