this for chaining.var.opAssign
var opAssign(T)(T rhs) @safeAssign from an arbitrary value rhs, setting the internal type and payload accordingly.
var that contains an ARRAY or
OBJECT, this operation performs a shallow copy — the underlying container reference is aliased, not duplicated. This means:
var a = var([1, 2, 3]);
var b = a; // b aliases a's array
b[0] = 99; // modifies a[0] as well!
assert(a[0].as!int == 99); // true — both see the changeTo create an independent copy, use dup() or idup():
var a = var([1, 2, 3]);
var b = a.dup(); // b has its own copy
b[0] = 99;
assert(a[0].as!int == 1); // a is unchangedThis shallow-copy behavior is intentional for performance (avoiding deep copies on every assignment), but users must be aware of the aliasing implications for container types.
Parameters
rhs | The value to assign. |
Returns
A reference to